To provide a user with a binary choice.
In other words an option that is yes.
Well now we use a checkbox a checkbox is an input element with the type of checkbox.
In the browser it's normally rendered as a square box that you can click to toggle on and off again.
If we add a value for the name attribute so that we can get it's value when it's submitted when we check
the box and submit the farm.
We get the name we supplied with the value of on.
If we go back and uncheck the box and then submit the farm there's nothing in the array.
Browsers don't send anything for empty check boxes.
By default the control has the value of on as we just saw.
You can change this however if you like by specifying a value for the value attribute.
Now if we check the box and submit the farm this is the value that is submitted.
Also by default a checkbox isn't checked when the farm is first loaded but we can change this by adding
the checked attribute similar to the selected attribute used in the select control we saw earlier.
Now when the pharmacy first loaded the check box is already checked.
The control doesn't include a label of any kind.
So to label a checkbox we just add some text or whatever content you like next to the control like that.
Note that you can't click on this text to toggle the checkbox.
You have to click directly on the checkbox itself.
We'll see how we can use the label element to achieve this next.
We can use checkboxes to give the user a list of options where they can choose as few are as many answers
as is necessary.
For example in answer to a question.
So let's add a question and several checkbox answers like that.
Now there are two ways we could get the values from these checkboxes.
The first is to give each checkbox a different name and not specify a value.
So if I select a couple of these and submit the farm we get the names of the checkboxes that I checked
as the indexes of the array with the values of.
On.
The other way we could do it is to give all the checkbox is the same value for the name attribute with
the empty square brackets at the end.
If we do this then we also have to provide values for the value attribute.
Different for each checkbox like this.
Now if I select a couple of boxes and submit the farm we get one element in the post array that contains
an array with each value that was checked.
Either method is a valid way to access the selected checkboxes Whichever method you choose.
Having multiple check boxes like this is more user friendly than the multiple select element that we
saw earlier.