troubleshooting Question

Checkboxes conflict -- javascript vs. PHP

Avatar of scrathcyboy
scrathcyboyFlag for United States of America asked on
15 Comments1 Solution473 ViewsLast Modified:
A form with 12 checkboxes, and an INPUT field associated with each, like --

form.elements [0]   checkbox   1         form [1]     input % associated with checkbox 1
form.elements [2]   checkbox   2         form [3]     input % associated with checkbox 2         ...up to 12 ckboxes

I wanted to NAME each checkbox different, with a value = 0, so I can test with javascript and set the VALUE of each checked checkbox to 1.   This way, when the form gets to PHP, I can look through the checkboxes for a value of 1, and if so, I can email the NAME of the checkbox and the input % associated with it -- e.g.

'The name called "ABC choice" has been assigned 40%'  and
'The name called "BBC choice" has been assigned 60%.'

That is the goal of the PHP.  Without a unique name for each checkbox, the input percents mean nothing.

But in PHP they say to NAME all checkboxes the same -- name="choice[]" -- square brackets puts them in an array, and the value is the name.  This method has problems, if nothing is checked, PHP returns a visible error, which is unacceptable (No return to the page, it all gets emailed to me).

WHAT I WOULD LIKE TO DO IS -- keep my original plan of names, and find a way in PHP to easily loop through all the checkboxes and related % inputs, finding only the ones with value=1, and email those results and percents as above.

The logic of how best to handle these checkboxes in PHP and working PHP code is my main concern here.
Can anyone help withPHP code to do it?   I've read most relevant links, so just ideas and code, please!  
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 15 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros