Jump to content

[SOLVED] Checking to see if checkbox option was checked or not?


galvin

Recommended Posts

If you have a form with several checkbox options like...

 

<input type='checkbox' class="" name='pooloptions[]' value="one" />1
<input type='checkbox' class="" name='pooloptions[]' value="two" />2
<input type='checkbox' class="" name='pooloptions[]' value="three" />3
<input type='checkbox' class="" name='pooloptions[]' value="four" />4

 

... and the form is submitted, you obviously have an array called "pooloptions[]' that holds the value of all options that were checked.

 

But if I want to say, for example, "If the checkbox option with a value of "two" was NOT checked, do this, else, if the option with a value of "two" WAS checked, do this", how would I do that?

 

I know it's simple but I'm confusing myself  :-\

 

Thanks,

Greg

 

check boxes that aren't checked don't get submit to the $_POST array

 

you can do something like

<input type='checkbox' class="" name='pooloptions[1]' value="one" />1
<input type='checkbox' class="" name='pooloptions[2]' value="two" />2
<input type='checkbox' class="" name='pooloptions[3]' value="three" />3
<input type='checkbox' class="" name='pooloptions[4]' value="four" />4

 

then you could do

if (isset($_POST['pooloptions'][2])){
//do whatever
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.