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'); }); 

fiddle


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -