I am writing a jquery code which aim is to disable/enable group of checkboxes. So far I got: Html:
<select id="Units"> <option value="Marketing" > Marketing </option> <option value="Finance" > Finance </option> <option value="Operations" > Operations </option> </select> <input type="checkbox" class="enable" onclick="check();" value="1"> chbx1 <input type="checkbox" class="dissable" onclick="check();" value="2"> chbx2 <input type="checkbox" class="dissable" onclick="check();" value="3"> chbx3 <input type="checkbox" class="enable" onclick="check();" value="4"> chbx4 JS
$("#Units").on("change", function() { if ($(this).val() !== "Finance") { $(".dissable").attr("disabled", "disabled"); } else { $(".dissable").removeAttr("disabled"); } }); But it doesn't work properly on the page load. Only after change the selected option the checkboxes react. How to improve this in order to catch selected value when the page is load and enabled/disabled checboxes with apropriate class?
changeevent manually or set initial values in HTML