Hi. I have form fields that when a user selects a checkbox they then enter a value in the option selection box. All works well, but I now need these values emailed, but only the ones that have been selected in the checkbox.
There’s no need to filter them beforehand. Instead, process them with PHP.
If a checkbox value exists (chk1) then you do something with the form value (txt1)
for ($i = 0; $i < $numberOfCheckboxes; i += 1) {
if (isset($_POST['chk' . $i])) {
// do stuff with ['txt' . $i]
}
}
That ensures that your form will work in all circumstances, regardless of whether client-side scripting is working or not.
After your server-side code is working well, you then apply over the top a thin veneer of JavaScript that helps the end-user by disabling or hiding the text fields until after a checkbox is checked.
Once you have your PHP code in place (for safety), only after that is when you should consider client-side scripting such as JavaScript.
… and made that script the target for your forms’ action …
then you would be able to see what was being sent to your script, click and unclick some boxes to see how the values change.
Either make conditional tests for each form element, or programatically loop through them looking for those which have been clicked or had data entered.
If you cannot work it out from there, distill that down to ONE OR TWO form elements, and post small examples of your html and the results of var_dump( $_POST ) and someone will be able to help you - but sending us a load of html and javascript to wade through is not conducive to getting you loads of quick answers.
Edit:
I see somone kind replied, but I’ll leave this advice, you need to learn how to divide and conquor if you want any chance of learning how to debug and develop yourself
I see what you are getting at pmw57, but the problem is when they are emailed that way I wont know which quantity for each item. Cause all that get emailed is the actual quantity numbers
I’m about to head off to work now, butit seems that you require a bit more than simple advise. I would suggest that you get in touch with someone so as to arrange a more one-on-one role of assistance.