Hey I just wanted to know how do we check if a user has checked a checkbox or not in a form after hitting the submit buttom . I am using PHP so any help regarding that would be really appreciated . Thanks
4
-
1Can you show us your effort?Mohit Mehta– Mohit Mehta2013-03-20 10:08:03 +00:00Commented Mar 20, 2013 at 10:08
-
can you post your checkbox code here?Dead Man– Dead Man2013-03-20 10:08:05 +00:00Commented Mar 20, 2013 at 10:08
-
<input name="agree" type="checkbox" value="Check" />Abhinav– Abhinav2013-03-20 10:15:34 +00:00Commented Mar 20, 2013 at 10:15
-
do some basic search before asking to stack..Shiju Shaji– Shiju Shaji2013-03-20 11:03:19 +00:00Commented Mar 20, 2013 at 11:03
Add a comment
|
3 Answers
You can do it like this:
if(isset($_POST['checkbox_name']) && $_POST['checkbox_name']!="")
{
echo 'checkbox is checked';
}
3 Comments
Abhinav
thanks I was using 'name' of the checkbox instead the 'value' .
Abhinav
Hey I have a little more doubt now , whats the difference between using a 'name' and 'value' in an input checkbox ?
Dead Man
name and value are totally different attributes of a checkbox. name is used to fetch the value of element, and value is the value of that element.HTML
<input type='checkbox' name='theName' value='itsChecked'>
PHP
if($_POST['theName'] == 'itsChecked'){}