Little confusion in multiple checkboxes

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Mar 2007
Posts: 22
Reputation: enggars is an unknown quantity at this point 
Solved Threads: 0
enggars enggars is offline Offline
Newbie Poster

Little confusion in multiple checkboxes

 
0
  #1
May 9th, 2007
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{
..........................
}
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 30
Reputation: azzu5 is an unknown quantity at this point 
Solved Threads: 2
azzu5 azzu5 is offline Offline
Light Poster

Re: Little confusion in multiple checkboxes

 
0
  #2
May 9th, 2007
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..
Looking at my own code of Life and thinking what the hell is this....
------------------------------------
Middle East B2B Marketplace
Dubai Web Design
Dubai SEO
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 22
Reputation: enggars is an unknown quantity at this point 
Solved Threads: 0
enggars enggars is offline Offline
Newbie Poster

Re: Little confusion in multiple checkboxes

 
0
  #3
May 10th, 2007
Originally Posted by azzu5 View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,210
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 166
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: Little confusion in multiple checkboxes

 
0
  #4
May 10th, 2007
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.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 2725 | Replies: 3
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC