form with checkboxes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Pavlos1316
Forum Newbie
Posts: 6
Joined: Mon Jun 02, 2008 4:17 am

form with checkboxes

Post 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
hansford
Forum Commoner
Posts: 91
Joined: Mon May 26, 2008 12:38 am

Re: form with checkboxes

Post 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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: form with checkboxes

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: form with checkboxes

Post 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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: form with checkboxes

Post 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.
hansford
Forum Commoner
Posts: 91
Joined: Mon May 26, 2008 12:38 am

Re: form with checkboxes

Post by hansford »

My appologies, same guy with same question, different website forums.
Post Reply