javascript - Disable other options in a dropdown, if clicked on the first option -
i have dropdown can select multiple options. if select 1 option in that, need rest of options disabled.
for example : in below code, if select option all, need rest of options disabled.
<select id="searchregion" name="searchregion" multiple="multiple"> <option> choose region(s) </option> <option value="all"> </option> <option value="east"> east </option> <option value="north"> north </option> <option value="west"> west </option> <option value="south"> south </option> </select>
try
var $searchregion = $('#searchregion').change(function() { var isall = $searchregion.find('[value="all"]').is(':selected'); if (isall) { $searchregion.val('all'); } $searchregion.find('option').not('[value="all"]').prop('disabled', isall); })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <select id="searchregion" name="searchregion" multiple="multiple"> <option>choose region(s)</option> <option value="all">all</option> <option value="east">east</option> <option value="north">north</option> <option value="west">west</option> <option value="south">south</option> </select>
Comments
Post a Comment