Connecting Tech Pros Worldwide Forums | Help | Site Map

Unchecking specified checkboxes in a table

Newbie
 
Join Date: Mar 2007
Posts: 2
#1: Mar 6 '07
I have a table with 12 checkboxes. I have the following function which when I check the last checkbox in the table, the first 10 checkboxes in the table are unchecked. -

function modify_boxes(to_be_checked,total_boxes){ for ( i=0 ; i < total_boxes ; i++ ){ if (to_be_checked){ document.forms[0].x[i].checked=true; } else{ document.forms[0].x[i].checked=false; } } }

I have the following in 'onclick' on the last checkbox in the table -

modify_boxes(false,10)

What I would like to happen, is when the first checkbox in the table is checked, that only the last two checkboxes in the table are unchecked. However the names of the checkboxes must all be 'x' as they are referenced elsewhere

thanks in advance

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Mar 6 '07

re: Unchecking specified checkboxes in a table


Geovanni, welcome to The Scripts.

Just use the same method, onclick and call a function:
Expand|Select|Wrap|Line Numbers
  1. function modifyLastTwo(checked) {
  2. var len = document.forms[0].x.length;
  3. document.forms[0].x[len-2].checked=checked;
  4. document.forms[0].x[len-1].checked=checked;
  5. }
with checked being either true or false, depending on the value of the first checkbox.
Newbie
 
Join Date: Mar 2007
Posts: 2
#3: Mar 6 '07

re: Unchecking specified checkboxes in a table


thanks a lot
Reply