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

ios - Memory not freeing up after popping viewcontroller using ARC -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -