/    Sign up×
Community /Pin to ProfileBookmark

limiting checkboxes in arrays

Can someone help me with limiting my guest to three checkboxes in each group??? I must be confused by the syntax–or possably thehole thing–.

<html>
<head>

<script language=”javascript”>
var checked1 = 0;
var checked2 = 0;
var checked3 = 0;
var maxnum = 3;
var i1;
var i2;
var i3;
var group1=””;
var group2=””;
var group3=””;
function getcheckboxs(what)
{
j=what.group1.length;
for (i=0; i<j; i++)
{
if(what.group1[i].checked)
{
if(checked < maxnum)
{
var group1 += what.group1[i].value;
checked++;
}
else
{
alert(‘You are only allowed to pick ‘ + maxnum + ‘ items’);
return false;
}

}
}
j=what.group2.length;
for (i=0; i<j; i++)
{
if(what.group2[i].checked)
{
if(checked < maxnum)
{
var group2 = what.group2[i].value;
checked2++;
}
else
{
alert(‘You are only allowed to pick ‘ + maxnum + ‘ items’);
return false;
}
j=what.group3.length;
for (i=0; i<j; i++)
{
if(what.group3[i].checked)
{
if(checked < maxnum)
{
var group3 = what.group3[i].value;
checked++;
}
else
{
alert(‘You are only allowed to pick ‘ + maxnum + ‘ items’);
return false;
}
}
what.buttons1.value = (group1)
what.buttons2.value = (group2)
what.buttons3.value = (group3)
what.buttons4.value = (group1+’, ‘+group2+’, ‘+group3)
}
</script>
<title>aa</title>
</head>
<body>

<form name=”myForm”>

<div onclick=”getcheckboxs(document.myForm)”><b>My group1:</b><input type=”checkbox” name=”group1″ value=”red”>
Red <input type=”checkbox” name=”group1″ value=”orange”>
Orange <input type=”checkbox” name=”group1″ value=”yellow”>

Yellow <input type=”checkbox” name=”group1″ value=”green”>Green
<input type=”checkbox” name=”group1″ value=”blue”> Blue
<input type=”checkbox” name=”group1″ value=”indigo”> Indigo <input type=”checkbox” name=”group1″ value=”violet”>
Violet <br>
<br>
<b>My group2:</b><input type=”checkbox” name=”group2″ value=”One”>1 <input type=”checkbox” name=”group2″ value=”Two”>
2 <input type=”checkbox” name=”group2″ value=”Thirty three”>
33 <input type=”checkbox” name=”group2″ value=”Fourty four”>

44 <input type=”checkbox” name=”group2″ value=”Five Hundred “>500
<br>
<br>
<b>My group3:</b><input type=”checkbox” name=”group3″ value=”a”>A <input type=”checkbox” name=”group3″ value=”b”>
B <input type=”checkbox” name=”group3″ value=”c”>C <input type=”checkbox” name=”group3″ value=”d”>
D <input type=”checkbox” name=”group3″ value=”e”>E </div>
<br>
<b>My Group1 Value:</b><input type=”text” name=”buttons1″ size=”50″><br>
<b>My&nbsp;</b><b>Group2</b><b> Value:</b><input type=”text” name=”buttons2″ size=”50″><br>
<b>My&nbsp;</b><b>Group3</b><b> Value:</b><input type=”text” name=”buttons3″ size=”50″><br>
<b>All&nbsp;</b><b>Groups</b><b> Values:</b><input type=”text” name=”buttons4″ size=”50″><br>
<br>
</form>

</body>
</html>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@NevermoreMay 28.2003 — This question has already been answered. See http://forums.webdeveloper.com/showthread.php?s=&threadid=7847
×

Success!

Help @gogotina spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...