>You should have these 2 lines outside of the function:
Sorry, forget this, I misread what you are doing... ;)
Main Topics
Browse All Topicsi have the following code that i need help reworking.
part 1
i want to only the user to only be able to click 3 check boxes or radio buttons.
but, if they change their mind, allow them to uncheck or unclick the radio button
and choose another answer.
part 2
i have other check boxes and radio buttons that i do not want to effect the
the maximum of 3 clicks on the same page. i need to exclude these from the
maximum 3 click choice.
i hope you all can help.
here is my code:
<HTML>
<HEAD>
<TITLE>Untitled</TITLE>
<SCRIPT TYPE="text/javascript">
function checkChecked(obj)
{
var maxchecked = 3;
var chkcount = 0;
var els = obj.form.elements;
for(var i=0; i<els.length; i++)
{
if(els[i].tagName.toLowerC
{
var typ = els[i].type.toLowerCase();
if((typ == 'checkbox' || typ =='radio'))
{
if(els[i].checked)
{
chkcount++;
}
if(chkcount > maxchecked)
{
obj.checked = false;
alert('Sorry, you can select only ' + maxchecked + ' choices');
break;
}
}
}
}
}
</SCRIPT></HEAD>
<BODY>
<FORM NAME="myform">
<P>
<FONT FACE="Arial,Helvetica,Mona
avaliable to click</FONT></FONT></P>
<P>
<FONT FACE="Arial,Helvetica,Mona
unclick check box to make a new choice, but still limit to 3 checks ]</FONT></FONT></P>
<P>
<FONT FACE="Arial,Helvetica,Mona
<P>
<FONT FACE="Arial,Helvetica,Mona
<P>
<FONT FACE="Arial,Helvetica,Mona
<P>
<FONT FACE="Arial,Helvetica,Mona
to be limited</FONT></FONT></P>
<P>
<FONT FACE="Arial,Helvetica,Mona
<P>
<FONT FACE="Arial,Helvetica,Mona
<P>
<FONT FACE="Arial,Helvetica,Mona
</FORM>
</BODY>
</HTML>
thanks
mike
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
You can "group" your checkboxes by giving them a class and pass that class to your function. Then limit will be based on that "common class". The checkboxes seem to be working. The radio buttons I didn't bother because I don't understand how you are "grouping" them, the idea is the same (in terms of the class)
hielo
this is what i was trying to say in my past post.
i know that the radio buttons have to be grouped seperate
this is my code with your class.NAME that i modified the buttons
<SCRIPT TYPE="text/javascript">
function checkChecked(obj,group)
{
var maxchecked = 3;
var chkcount = 0;
var els = obj.form.elements;
for(var i=0; i<els.length; i++)
{
if(group && els[i].className==group && els[i].checked && els[i].tagName.toLowerCase
{
var typ = els[i].type.toLowerCase();
if((typ == 'checkbox' || typ =='radio'))
{
if(els[i].checked)
{
chkcount++;
}
if(chkcount > maxchecked)
{
obj.checked = false;
alert('Sorry, you can select only ' + maxchecked + ' choices');
break;
}
}
}
}
}
</SCRIPT></HEAD>
<BODY>
<FORM NAME="myform">
<P>
<FONT FACE="Arial,Helvetica,Mona
avaliable to click</FONT></FONT></P>
<P>
<FONT FACE="Arial,Helvetica,Mona
unclick check box to make a new choice, but still limit to 3 checks ]</FONT></FONT></P>
<P>
question # 1</P>
<P>
<INPUT TYPE=CHECKBOX ONCLICK="checkChecked(this
<P>
<FONT FACE="Arial,Helvetica,Mona
<P>
<INPUT TYPE=CHECKBOX NAME=" " ONCLICK="checkChecked(this
<P>
<FONT FACE="Arial,Helvetica,Mona
<P>
<FONT FACE="Arial,Helvetica,Mona
to be limited</FONT></FONT></P>
<P>
<INPUT TYPE=CHECKBOX NAME=" "><FONT FACE="Arial,Helvetica,Mona
</FORM>
</BODY>
</HTML>
if i have 2 or more questions and i want just 3 possible answers to each question,
how do i name each class.NAME seperate?
HONORGOD:
can you give me the whole code with the buttons as per you last selection?
>>If i have 2 or more questions and i want just 3 possible answers to each question, how do i name each class.NAME seperate?
You give each question's checkbox group it's own classname. So for all of q1 checkboxes you would add class="q1", for all of q2 checkboxes you can use class="q2" etc. I used a class because YOU did not name your checkboxes, but if you were to give all of q1 checkboxes the same name => name="q1", then you will NOT need the class and instead of checkChecked(this,this.cla
BTW: when posting code, click on Attach Code Snippet and place it there.
Business Accounts
Answer for Membership
by: TNamePosted on 2008-05-14 at 13:51:36ID: 21568566
You should have these 2 lines outside of the function:
('theName' );
var chkcount = 0;
var maxchecked = 3;
(especially "var chkcount = 0;" otherwise the count will start from zero every time you click and you'll never reach 3...)
Also, you could give all checkboxes/radiobutons that you want to include the same name and then say:
var els = document.getElementsByName