halofourteen halofourteen - 9 months ago 53
HTML Question

disable editing default value of text input

I have a search form

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

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.

Answer Source

You can either use the readonly or the deactivated attribute. Note that when deactivated, 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">