javascript - check checkbox based on dropdown -
i wondering if there way auto check boxes based on value dropdown selection. have been searching forever , can seem find ways show or hide checkboxes based on dropdown not looking for.
you can pretty jquery. code listens change event dropdown id="dropdown"
, checks checkbox id="checkbox"
if dropdown text equal 'foo'.
$("#dropdown").change(function() { if($('#dropdown :selected').text() === 'foo') $('#checkbox').prop('checked', true); });
if want uncheck box when selection changed again might better:
$("#dropdown").change(function() { var text = $('#dropdown :selected').text(); $('#checkbox').prop('checked', text === 'foo'); });
Comments
Post a Comment