Page 1 of 1
form with checkboxes
Posted: Sat Jun 14, 2008 10:53 am
by Pavlos1316
Hi to all (quite new still)
I have a form with checkboxes. It works fine.
It has 24 columns. 8 rows X 3 colums each.
I need when the form is submited to check if:
1. every row has at least 1 column checked
2. there are no more than 9 columns checked.
That means one column checked in every row exept one that will have 2 columns checked.
Can anyone help me?
Thanks
Re: form with checkboxes
Posted: Sat Jun 14, 2008 12:32 pm
by hansford
You've posted this same question 3 times already. And it's been answered twice and I'll answer again. USE javascript. Go look it up, learn, be happy.
Re: form with checkboxes
Posted: Sat Jun 14, 2008 2:41 pm
by califdon
I've checked and didn't find any previous postings of this question by Pavlos1316. Perhaps someone else had a similar question. Please try to not flame other members before checking carefully. Thank you.
Re: form with checkboxes
Posted: Sat Jun 14, 2008 2:47 pm
by RobertGonzalez
And why in the world would you rely on Javascript to handle something the server should be checking for anyway?
To the OP, you have written out the logic that you need to follow. Now write some code that matches that logic. Try what you have coded on your local server and if it borks, ask us questions to get you moving along.
Re: form with checkboxes
Posted: Sat Jun 14, 2008 3:30 pm
by califdon
Everah wrote:And why in the world would you rely on Javascript to handle something the server should be checking for anyway?
It seems to me it would be reasonable to do that validation in Javascript before submission, though, as an onClick event of the Submit button, so that it would only actually submit a valid request.
As Everah said, you just need to convert the logic you expressed into code. If you will always have the same configuration and rules, you could do it with a series of If statements. I think I would assign a value of 1 (numeric one) to a checked box, so it would be easy to do something like:
Code: Select all
if ((getElementById('chkbx1') + getElementById('chkbx2') + getElementById('chkbx3') == 1)
AND (getElementById('chkbx4') + getElementById('chkbx5') + getElementById('chkbx6') == 1)
AND (getElementById('chkbx5') + getElementById('chkbx6') + getElementById('chkbx7') == 1)
...
AND (getElementById('chkbx22') + getElementById('chkbx23') + getElementById('chkbx24') == 2) {
document.myFormName.submit()
} else {
// give user an alert to correct their entry
}
I haven't thought that through very carefully, but something like that.
Re: form with checkboxes
Posted: Sat Jun 14, 2008 7:00 pm
by hansford
My appologies, same guy with same question, different website forums.