on selecting values from the drop down, if the selected values equals to a certain value, i want the dropdown to change to readonly, how can i do that?
HTML:
<select id="s_id">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option></select>
Script:
$(document).ready(function () {
$("#s_id").change(function () {
var x = $(this).val();
//alert("something's changed");
alert($(this).val());
if (x === opel) {
alert("iff only.....");
$(this).attr("readOnly", "true");
}
});
});
if (x === "opel").... Secondly and more importantly,selectelements cannot be madereadonly. They can bedisabled, but their value would then not be sent with the form data.if (x == opel) {, variableopelis undefined. You probably wanted to compare against String;if (x == 'opel') {propinstead ofattr