English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i have these two checkboxes:



How can i check or uncheck both the checkboxes using javascript.
If i don't use array but still use the same checkbox name, the following works

function checkAll(field){
for (i=0; i < field.length; i++)
field[i].checked = true;
}

if i pass (onClick=checkAll(document.form.gender))

2006-07-16 23:56:14 · 2 answers · asked by Manish 5 in Computers & Internet Programming & Design

2 answers

I still think you should just change them so they have different names. It might seem like more work in the short term, but in the long term it'll save you even more, and it'll get you out of the bad programming practice of name duplication :P

2006-07-17 00:03:24 · answer #1 · answered by Anonymous · 0 4

you should be able to loop through them and just not use names.

if they are the only checkboxes in the form just do something like this:

for (x=0; x <= form.elements.length; x++){
if (form.elements[ x ].type == "textbox"){
//do stuff
}
}

2006-07-17 07:26:16 · answer #2 · answered by John J 6 · 0 0

fedest.com, questions and answers