What I have is a form and within this form I have a set of checkboxes. There is a master checkbox, which once clicked it should enable all checkboxes and textfields under it.
It will probably be much easier if I give you an example of what I want to achieve.
When you click on the “enable_bin_ALL” checkbox, it should enable the “buy_it_now_ALL” box and also should enable the following checkbox and textfields:
Thanks for your suggestion, but I forgot to mention that I need to do it dynamically and there will be a lot more checkboxes to enable than the 2 I posted. I was thinking of making an onClick event, but would like to keep the JavaScript separate in a JavaScript file.
function enableBIN(){
for(var i=0; i<document.addconfig.elements.length; i++)
{
var el = addconfig.elements[i];
if(el.name && (el.name.substr(0, 6) == 'enable' || el.name.substr(0, 6) == 'buy_it'))
el.checked = document.addconfig.checked;
}
}
I then triggered it with an onClick event on the master checkbox, but it doesn’t work. Note: I changed this.form to “document.addconfig” as the form has the id/name “addconfig”.
document.addconfig.checked should be document.addconfig.enable_bin_ALL.checked
var el = addconfig.elements[i]; should be var el = document.addconfig.elements[i];