javascript - Disable certain options in a drop down select -
need disable option "5" & "6" when option value "2" selected. should display options in list_2 when option "1" selected. how can using jquery or other method.
if ($('option[value=2]').prop('selected', true)) { $('option[value=5]').prop('disabled', true); }
<html> <body> <select id= "list_1"> <option value="1">option 1</option> <option value="2">option 2</option> </select> <select id= "list_2"> <option value="4">option 4</option> <option value="5">option 5</option> <option value="6">option 6</option> </select> </body> </html>
with plain js:
document.getelementbyid('list_1').onchange = function() { document.getelementbyid('list_2')[1].disabled = (document.getelementbyid('list_1').selectedindex == 1); document.getelementbyid('list_2')[2].disabled = (document.getelementbyid('list_1').selectedindex == 1); }
<select id="list_1"> <option value="1">option 1</option> <option value="2">option 2</option> </select> <select id="list_2"> <option value="4">option 4</option> <option value="5">option 5</option> <option value="6">option 6</option> </select>
Comments
Post a Comment