HTML - Checkbox

by
Jeremy Canfield |
Updated: March 11 2020
| HTML articles
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.
Did you find this article helpful?
If so, consider buying me a coffee over at