views:

179

answers:

4

Hello!

I have three checkboxes like ch[0], ch[1] and ch[3] (sometimes i have more, or less, it's dinamic) and in PHP i want to get the unselected items also, like this: 0=yes,1=no,3=yes and so on.

Can I solve this somehow?

+3  A: 

A common way is to put a hidden form field beside the checkbox and then via javascript set the value for that when the checkbox is changed.

EDIT: You don't need javascript. But the hidden field is a way to go, when you don't neccessarily know, on the page that is posted to, how many checkboxes there are on the requesting page. Check out: http://www.felgall.com/xtutf06a.htm

asgerhallas
Well, you actually don't need the scripting it seems: http://www.felgall.com/xtutf06a.htm
asgerhallas
Edited the post to include the link from my previous comment.
asgerhallas
+1  A: 

Unselected checkboxes are not being submitted. So you can only determine the unselected checkboxes by determining the set of all available checkboxes minus the selected checkboxes.

Gumbo
+1  A: 

Why do you need the unselected ones if you have both the complete list and the selected ones in the server side? Just extract the unselected ones from the complete list by filtering the selected ones out.

BalusC
It's complicated to explain, but asgerhallas's solution was the easiest to make it quick.
Gero
A: 

You can do this on HTML:

<input type="hidden" name="ch[0]" value="no">
<input type="checkbox" name="ch[0]" value="yes">
...
<input type="hidden" name="ch[5]" value="no">
<input type="checkbox" name="ch[5]" value="yes">

And check it the regular way on PHP:

<?php
  $ch = $_REQUEST['ch'];
  //then use $ch[0], $ch[1], ..
?>
Carlos Lima