user906153 user906153 - 7 months ago 16
HTML Question

Check a checkbox on a dropdown selection

I'm looking for a way to automatically check a checkbox when a selection is made from a dropdown. The HTML code looks something like this:

<input type="checkbox" name="check1" />Process 1:</td>
<select id="process1" name="process1">
<option value="null">--Select Process--</option>
<option value="NameA">NameA</option>
<option value="NameB">NameB</option>
<option value="NameC">NameC</option>

If possible, if the user goes back and selects
--Select Process--
, the checkbox would uncheck

What would the Javascript code look like for this?

    $('#process1').change(function() {
        var selected = $('#process1 option:selected');
        if (selected.val() == "null") {
            $('input[name="check1"]').prop('checked', false);
        else {
            $('input[name="check1"]').prop('checked', true);