<form id="myForm" action="http://www.PuStudy.Com/resources/html-forms-action.html"> <select name="Food" required> <option value=""></option> <option value ="apples">Apples</option> <option value ="bananas">Bananas</option> <option value ="oranges">Oranges</option> </select> <button>Submit</button> </form>
The above example demonstrates usage of the
<select> element with the
Click Submit without selecting an option from the
<select> list. Your browser should prevent the form from being submitted, and it should ask you to make a selection from that form control.
required attribute specifies that the
<select> list is a required option for form submission. In other words, a selection must be made before the form can be submitted to the server.
You can test this in the above example by attempting to submit the form without selecting an option from the
required attribute is a boolean attribute. If it is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace (i.e. either