Skip to content Skip to sidebar Skip to footer

Uncheck Checkbox When Certain Values From Drop Down Is Chosen

I need to uncheck my checkbox when i choose a certain value from my drop down list or when the user does not select any value from the drop down list. Im using Jquery at the moment

Solution 1:

Assuming the only time you want the check box checked is when completed is selected:

 $("#drop1").on('change', function () {
    varval = $(this).val();
    if (val === " " || val === "In Process" || val === "KIV") {
        $('#checkbox1').prop('checked', false);
        return;
    }
    $('#checkbox1').prop('checked', true);
});

and html:

<selectclass="form-dropdown"id="drop1"name="drop1"><optionvalue=" "></option><optionvalue="In Process">In Process</option><optionvalue="KIV">KIV</option><optionvalue="Completed">Completed</option></select><inputtype="checkbox"id="checkbox1"name="checkbox1"/>

Here is a FIDDLE

Solution 2:

You need to actually bind the call to sdp4 to something:

$("#drop1").on('change', sdp4);

At that point it would also be redundant to use #drop1 in the selectors when you could use this.

Solution 3:

Try this: http://jsfiddle.net/7cqDB/

functionsdp4(str) {
  if (str == '' || str == "In Process" || str == "KIV") {
      $('#checkbox1').prop('checked', false);
  } else {
      $('#checkbox1').prop('checked', true);
  }
}

$(function () {
   $('select').on('change', function () {
       var str = $(this).val();
       sdp4(str);
   });
});

Post a Comment for "Uncheck Checkbox When Certain Values From Drop Down Is Chosen"