View Single Post
Old 01-05-2013, 04:34 PM   PM User | #1
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 612
Thanks: 19
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
Checking if Check-Box is Checked!!

What is the best way to check if a Check-Box is checked?!

Here is my HTML...
Code:
	<input name='selectAll' type='checkbox' value=1 />

In my PHP, I originally had been using this...
PHP Code:
    if (!empty($_POST['selectAll']) && $_POST['selectAll'] == 1){ 

However, in retrospect this seems like overkill...

If the Check-Box was not checked, then it would have a value of "NULL", right?

And if the Check-Box was checked via the Form, it would have a value of "1", right?

And if some hacker were screwing with things, it would have some other value, right?

But in this instance, all I really care about is if selectAll = 1, so couldn't I just write this instead...
PHP Code:
    if ($_POST['selectAll'] == 1){
        
// Do something.

    
}else{
        
// Do nothing.

    

Sincerely,


Debbie
doubledee is offline   Reply With Quote