/    Sign up×
Community /Pin to ProfileBookmark

Help needed with checkboxes in form

Hope someone can start me off in the right direction on how I can achieve the following.

Page1
Within form is a list of 100 questions each with their own checkbox, however the user must select to answer only 10 of these questions. So they select the 10 questions they wish to answer.

Page2
Then display the 10 questions they selected.

I believe this is something straightforward, just i cant get started.

Many thanks for the assistance.

Jon

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@holyhttpMay 07.2007 — You need to write a javascript function that goes through all check boxes to see what is the status of each one "checked" or not.

Then using a counter within that function you can determine how many of those checkboxes are checked.

function HowMany(myform){

var k=0; //counter for the selected check boxes

for(var i=0; i<myform.elements.length; i++){

if( (myform.elements[i].type=='checkbox') && (myform.elements[i].checked)){

$k++;

}

if(k>=10){

alert('Only 10 options can be selected');

return false;

}



}//endfor loop



}//end function



Obviously the loop only work if the only check boxes in your form are the one the user can select only up to 10. Otherwise you can create an array filled with the name of all the check boxes the user can choose from and loop through that array.



Hope that will give you a jumpstart.
Copy linkTweet thisAlerts:
@dr_overloadauthorMay 07.2007 — Thanks holyhttp, that has definately helped.
×

Success!

Help @dr_overload 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.18,
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,
)...