HTML Checkbox

Home > Search
  by

A checkbox can be used to do something when the checkbox is selected. 

<form method="post" action="/example.php">
  <input type="checkbox" name="option" value="you selected option 1"> Option 1 <br />
  <input type="checkbox" name="option" value="you selected option 2"> Option 2 <br />
  <input type="checkbox" name="option" value="you selected option 3"> Option 3 <br />
  <input type="submit" value="Submit">
</form>

 

In this example, there will be three check boxes and a submit button.

 

You can then use a programming language to do something based on the check box that was selected. In this example, PHP is used to display the option that was selected. You could do something similar in other programming languages, such as C or Java.

<?php
   $myOption = $_POST['option'];
   echo $myOption;
?>

 

In this example, after selecting option 1 and selecting Submit, "you selected option 1" is displayed.



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments