Jump to content


Photo

Checkbox Help


  • Please log in to reply
4 replies to this topic

#1 EmperorDoom

EmperorDoom
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 09 August 2006 - 08:47 PM

Hey guys, I need help with this one:
I have a form set up with checkboxes. I know how to get an array of the boxes that were checked, but is there anyway to get an array of the boxes that were unchecked? (as in the user clicked them off after they were already checked when the form loaded)
Thanks

#2 ScottRiley

ScottRiley
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 09 August 2006 - 09:23 PM

I'm not sure of the validation you're using, or how one would go about checking if a box was checked, but if the code involved (Pseudo-code here:)

if(box_is_checked);

could you not just add an '!'

if(!box_is_checked);


#3 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 09 August 2006 - 09:27 PM

No, you can't. Only checked checkboxes are submitted, so if you want to know which were left unchecked, your script must know what checkboxes exist.
~ D Kuang

#4 ScottRiley

ScottRiley
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 09 August 2006 - 09:29 PM

Ok, cool, I was just thinking, not really up on PHP  :D

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 09 August 2006 - 09:30 PM

That will not work, since only those checkboxes that are checked are returned to your script.

You could set up an array of all possible checkbox names and then check if the names are set in $_POST, if the name isn't set, the check box wasn't checked.

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users