Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable/Disable other elements based on selection

<select name="feature1">
  <option value="1">Enable</option>
  <option value="0">Disable</option>
</select>

<input type="checkbox" name="feature2" />
<input type="checkbox" name="feature3" />

How do I disable 'feature2' and 'featured3' inputs when 'disable' in 'feature1' is selected?

Thanks

like image 872
eozzy Avatar asked Apr 25 '26 02:04

eozzy


2 Answers

This automatically enables the items again when 'Enable' is selected, which I assume is also what you want.

$('select[name=feature1]').change(function() {
   $('input[name=feature2],input[name=feature3]').attr('disabled', $(this).val() == '0');
});
like image 131
David Hedlund Avatar answered Apr 27 '26 20:04

David Hedlund


I'm going to assume you have ID's the same as your element names, for simplicity

jQuery('#feature1').change(function() {
   jQuery("#feature2, #feature3").attr("disabled", jQuery(this).val() == '0'); 
});
like image 35
Gareth Midwood Avatar answered Apr 27 '26 20:04

Gareth Midwood



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!