944,132 Members | Top Members by Rank

Ad:
May 9th, 2007
0

Little confusion in multiple checkboxes

Expand Post »
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{
..........................
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
enggars is offline Offline
22 posts
since Mar 2007
May 9th, 2007
0

Re: Little confusion in multiple checkboxes

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..
Reputation Points: 10
Solved Threads: 2
Light Poster
azzu5 is offline Offline
30 posts
since May 2007
May 10th, 2007
0

Re: Little confusion in multiple checkboxes

Click to Expand / Collapse  Quote originally posted by azzu5 ...
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....
Last edited by enggars; May 10th, 2007 at 2:08 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
enggars is offline Offline
22 posts
since Mar 2007
May 10th, 2007
0

Re: Little confusion in multiple checkboxes

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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. for(i=1;i<=3;i++) {
  2. tmp1 = document.form1.status[i].checked;
  3. alert(tmp1);
  4. if(tmp1){
  5. ..........................
  6. }
  7. else{
  8. ..........................
  9. };
  10. };
It seems to be the only way to do it with radio buttons.
Last edited by MidiMagic; May 10th, 2007 at 3:49 am.
Reputation Points: 730
Solved Threads: 181
Nearly a Senior Poster
MidiMagic is offline Offline
3,314 posts
since Jan 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: JS generated page 'save as' issues
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: is there an anlternative to Snap Shots™?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC