I am looking for a jQuery plugin that does this.
eg:
<label><input type="checkbox" depends_on="foo=5" name="boo" ... /> Check </label> <select name="foo" ... > <option value="5" selected="selected">5</option> <option value="15">15</option> <option value="25">25</option> </select>
therefore, the checkbox will be enabled only if option "5" is selected.
or
<select name="foo" depends_on="boo" ... > <option value="5" selected="selected">5</option> <option value="15">15</option> <option value="25">25</option> </select> <label><input type="checkbox" name="boo" ... /> Check </label>
In this case, the selection should only be enabled if the "boo" flag is checked.
I managed to create code that does something like this:
$("*[depends_on]").each(function(){ var source = $(this); var dep = $(this).attr('depends_on'); var target = dep.split("="); $("*[name='"+target[0]+"']:not(:hidden)").change(function(){ if($(this).attr('checked')) { source.removeClass('disabled'); source.removeAttr('disabled'); } else{ source.attr('disabled', 'disabled'); source.addClass('disabled'); } }).change(); });
it seems to work fine for choices that depend on the radio stations, but I want to implement this for any type of input or combination (or at least for most of them), without having to write separate code for each type of input.
Anyway, does anyone know about such a plugin? or maybe there are suggestions for my code above? :)
javascript jquery html input forms
Alex
source share