Does the select element have the required attribute?

HtmlAttributesHtml Select

Html Problem Overview


Does the select element have the required attribute?

Html Solutions


Solution 1 - Html

Yes you can use required attribute in HTML5. But remember, first value should be empty.

<select required>
<option value="">Please select</option>
<option value="first">First</option>
</select>

Here you get the more example:

http://dev.w3.org/html5/spec-author-view/the-select-element.html#the-select-element

Solution 2 - Html

Yes it has a required attribute, you can use it as follows

<select required>
<option value="" disabled selected>Choose</option>
<option value="first Option">First Option</option>
<option value="Second Option">Second Option</option>
</select>

Reference :

HTML Select required Attribute (W3C)

Solution 3 - Html

You can do this way to make it look better

    <select required>
    <option hidden="" disabled="disabled" selected="selected" value="">Select subject</option>
    <option value="first Option">First Option</option>
    <option value="Second Option">Second Option</option>
    </select>

Solution 4 - Html

Yes it does, but currently it is not supported by any version of all major browsers. This includes Safari, Chrome, Firefox, and IE.

Solution 5 - Html

It is possible but (just Arif said above) it is important (obviously) that you use the first option without value like:

<form action="#" method="post">
  <div>
    <label for="State">State</label> 
    <select required id="State" name="State">
      <option value="">Choose</option>
      <option value="new">New</option>
      <option value="old">Old</option>
    </select>
  </div>
</form>

You can see more info at: http://www.maxdesign.com.au/2012/11/03/select-required/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCodlerView Question on Stackoverflow
Solution 1 - HtmlAriful IslamView Answer on Stackoverflow
Solution 2 - HtmlAbubakar Ahmed RumaView Answer on Stackoverflow
Solution 3 - Htmlkamau wairegiView Answer on Stackoverflow
Solution 4 - HtmlIdris ArmstrongView Answer on Stackoverflow
Solution 5 - HtmljuanmjimenezsView Answer on Stackoverflow