Posts Tagged ‘jquery’

jQuery enable-disable elements

Let’s summarise here how to disable, enable, check, assign values and get selected values from your html document.

1
2
3
4
5
<select name="client.idClient" id="idClient">
<option value="1">CLIENT 1</option>
<option value="2">CLIENT 2</option>
<option value="3">CLIENT 3</option>
</select>

You can disable an element by setting the disabled attribute to disabled:

1
jQuery("#idClient").attr("disabled","disabled");

And enable the element by removing the disabled attribute:

1
jQuery("#idClient").removeAttr("disabled");

If the element is an input:

1
<input type="checkbox" id="yes"/>

then you have to [...]