Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable editing default value of text input

Tags:

html

I have a search form

<input id="price_from" value="price from "> <input id="price_to" value="price to "> <button>search</button> 

How can I disable editing of dafault text? When user starts to type in price amount it's not possible to edit "price from " and "price to " but they stay in input field. I've tried different mask plugins for jquery but they didn't show default text untill you focus on field and don't provide option for custom text. Only placeholders an chars.

like image 639
halofourteen Avatar asked Dec 04 '12 11:12

halofourteen


People also ask

How do I disable input field typing?

The disabled attribute is a boolean attribute. When present, it specifies that the <input> element should be disabled. A disabled input element is unusable and un-clickable.

How can you prevent users from editing an input's contents using html5?

You can't prevent users from modifying, adding or removing elements in the DOM. If you want that kind of control you should store the values of the elements you are outputting in an object and then compare what's coming in with the form post.


2 Answers

You can either use the readonly or the disabled attribute. Note that when disabled, the input's value will not be submitted when submitting the form.

<input id="price_to" value="price to" readonly="readonly"> <input id="price_to" value="price to" disabled="disabled"> 
like image 144
chrki Avatar answered Sep 27 '22 22:09

chrki


I'm not sure I understand the question correctly, but if you want to prevent people from writing in the input field you can use the disabled attribute.

<input disabled="disabled" id="price_from" value="price from "> 
like image 37
Schoof Avatar answered Sep 28 '22 00:09

Schoof