Jump to content

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


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
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.