954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Little confusion in multiple checkboxes

Hello, i have a multiple checkbox that needs checking.
So i build some validation code through javascript.
I found some problem in setting the name of checkbox in a loop.
The loop should check three checkboxes.

Which are status1, status2, and status3.
You might want to see my code below.
It doesnt work.
Anybody please helps.....
Thanks.....

The code:

for(var i=1;i<=3;i++) {
if(document.form1.status+i.checked){
..........................
}else{
..........................
}

enggars
Newbie Poster
22 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

try this...

for(i=1;i<=3;i++) {
tmp = "status" + i;
tmp1 = "document.form1." + tmp ;
alert(tmp1);
if(tmp1.checked){
..........................
}else{
..........................
}

This will work...

Cheers..

azzu5
Light Poster
30 posts since May 2007
Reputation Points: 10
Solved Threads: 2
 

try this...

for(i=1;i<=3;i++) { tmp = "status" + i; tmp1 = "document.form1." + tmp ; alert(tmp1); if(tmp1.checked){ .......................... }else{ .......................... }

This will work...

Cheers..

Hi, thanks for the help.
But your code need some modification to make it work.
here is the modification:


for(i=1;i<=3;i++) {
tmp = "status" + i;
tmp1 = "document.form1." + tmp ;
tmp2 = tmp1+".checked";
if(tmp2){

..........................
}else{
..........................
}

Many thanks for the help azzu....

enggars
Newbie Poster
22 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

Another way is shown oin the third post of my thread:

An array of arrays of of radio buttons

I gave all three checkboxes the same name. Then it was simple to do:

for(i=1;i<=3;i++) {
  tmp1 = document.form1.status[i].checked;
  alert(tmp1);
  if(tmp1){
    ..........................
  }
  else{
    ..........................
  };
};



It seems to be the only way to do it with radio buttons.

MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You