Acmlm's Board - I2 Archive - Programming - Select/Unselect all
User Post
Zem
Posts: 215/1107
If you're using a script (e.g. php) which could generate any number of checkboxes, it's more efficient to run through every element in the form and check it if it's a checkbox. Not that I remember how to do that, but I thought I'd point that out. =(
Mercury
Posts: 37/88
Thanks, very helpful !
Modereb
Posts: 67/75
Originally posted by neotransotaku I believe it is related to DOM manipulation and you have to get a hold of all the checkboxes, and for each checkbox, you set it. Although the following information is for Mozilla, the same approach works for IE:Explanation of relationship between DOM and Javascript DOM information from W3 You're been talking about the DOM in almost every JavaScript related thread lately but you rarely come up with an actually useful answer... Anyway... Checkbox 1 Checkbox 2 Checkbox 3<form name="cboxform"> <input type="checkbox" name="cbox1" /> Checkbox 1 <input type="checkbox" name="cbox2" /> Checkbox 2 <input type="checkbox" name="cbox3" /> Checkbox 3 <input type="button" value="Select all" onclick="document.forms.cboxform.cbox1.checked=1; document.forms.cboxform.cbox2.checked=1; document.forms.cboxform.cbox3.checked=1;" /> <input type="button" value="Unselect all" onclick="document.forms.cboxform.cbox1.checked=0; document.forms.cboxform.cbox2.checked=0; document.forms.cboxform.cbox3.checked=0;" /> </form>
neotransotaku
Posts: 1449/4016
I believe it is related to DOM manipulation and you have to get a hold of all the checkboxes, and for each checkbox, you set it. Although the following information is for Mozilla, the same approach works for IE:Explanation of relationship between DOM and Javascript DOM information from W3
Mercury
Posts: 35/88
I know you have to do it in Javascript, and I've search around a bit for free scripts, but none kinda worked . How could I select or unselect all checkboxes on a form with one click?