Solved

checkbox 2 sets.. validations

Posted on 2002-03-12
15
315 Views
Last Modified: 2012-08-14
halo folks

how wud u validate the following
assume a and b are 2 differnt table having a sets of checkbox

table A has 3 check boxes

table B has 10 checkboxes + select ALL check box which wil check/uncheck all the 10 checkboxes

i am generateing all the 10 checkboxes in a LOOP
<%for i= 1 to 10.....<input type=checkbox name=check<%=i%>><%next%>

my validation needed here is of 2 types:

1).if i select ALL in Table B ,i shud be able to choose only one checkbox in Table A

for e.g
 i choose ALL and i choose 1 in Table A.now if i try to check on 2 in table A its shud alert.."oops no multiple checking allowed for this combination"
vice versa must also be true i.e if i chose checkbox 1,3 in table A i shud NOT be able to check ALL in Table B

2).if i select more than 1 check box in Table B ,i shud be able to select only one chekbox in table A

for e.g
if i choose check box 2 and checkbox 7 in table B and i chose checkbox 2 in Table A.now if i try  to check on checkbox 1 in table A its must alert me in same way
it shud be true vice versa also

assume this as a mock template.

A  B
1  1
2  2    
3  3
   4
   5
   6
   7
   8
   9
   10
   ALL


hope i made it clear....
thanks in advance folks
pgnath
0
Comment
Question by:pgnath
  • 8
  • 5
  • 2
15 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 6858019
Okay, so the checkboxes for the B table are check1, check2...check10, but what are the names for the A table checkboxes?

Fritz the Blank
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 6858027
Here is part of the code:

iCheckedB =0
for(i=1;i<11;i++){
   if(eval('document.forms[0].check' + i)){
      iCheckedB = iCheckedB +1;
      }
   }

Fritz the Blank
0
 

Author Comment

by:pgnath
ID: 6858038
its named as checkbox1,checkbox2,checkbox3
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 6858060
function countChecks()
{
iCheckedA = 0
for(i=1;i<4;i++){
  if(eval('document.forms[0].checkbox' + i)){
     iCheckedA = iCheckedA +1;
     }
  }


iCheckedB = 0
for(j=1;j<11;j++){
  if(eval('document.forms[0].check' + j)){
     iCheckedB = iCheckedB +1;
     }
  }

if(iCheckedB >1 && iCheckedA >1){
   alert("If any items in B are checked, you can check only 1 A");
   return false;
}

return true;

}
0
 

Author Comment

by:pgnath
ID: 6858102
Fritz
wht is the event causing the countchecks() to happen???
thanks
Pgnath
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 6858133
When do you want to validate?

<form action="http://www.FairfieldConsulting.com" onSubmit="return countChecks()")

The above will fire the code when one goes to submit the form. If you want it to fire every time someone clicks on a checkbox, then:

<%for i= 1 to 10.....<input type=checkbox name=check<%=i%> onCick="javascript:countChecks()"><%next%>

Fritz the Blank
0
 

Author Comment

by:pgnath
ID: 6858272
fritz i am not combining the ALL checkbox along with the 10.so will it hold good even for that ALL checkbox???

Pgnath
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 75 total points
ID: 6858289
If you want to add the code to the onClick event for the other boxes, just do it as follows:

<input type=checkbox name=checkbox1 onCick="javascript:countChecks()">

<input type=checkbox name=checkbox1 onCick="javascript:countChecks()">

<input type=checkbox name=checkbox3 onCick="javascript:countChecks()">

Fritz the Blank
0
 

Author Comment

by:pgnath
ID: 6858496
ok lemme try now and wil let u know
0
 

Author Comment

by:pgnath
ID: 6858688
fritz its not this way
if i select more than 1 checkbox in B then only it shud say "only one check box can be checked in A"

as per ur code its saying that alert even if i select one checkbox in B.

also its giving me that alert even if i am unchecking the checkbox

was my question clear???
pls lemme know
Pgnath
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 6858724
You can change the message text to whatever you like. As I understand it, if more than one checkbox in B is selected, you can select only 1 box from A. Is that correct?

Fritz the Blank
0
 
LVL 12

Expert Comment

by:ahosang
ID: 8076158
This question has been abandoned. I will make a recommendation to the moderators on its resolution in a week or so. I appreciate any comments that would help me to make a recommendation.
 
In the absence of responses, I may recommend DELETE unless it is clear to me that it has value as a PAQ. Silence = you don't care
 
ahosang
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8076338
I feel that I put in the effort here--it is not my fault if pgnath dropped out.

Fritz the Blank
0
 
LVL 12

Expert Comment

by:ahosang
ID: 8234550
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

points to fritz_the_blank
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
ahosang
EE Cleanup Volunteer
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8234571
Thanks.

This didn't really get resolved, but it wasn't clear what pgnath wanted, and s/he bailed.

Fritz the Blank
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now