简体   繁体   中英

Select box validation is having problem after adding a required attribute

I got a problem when I'm validating this. I can't understand how do I fix it?

 <Label for="religion">Select Your Religion</Label> <select required class="form-control" id="religion"> <option disabled>Select Your Religion</option> <option value="hindu">Hindu</option> <option value="muslim">Muslim</option> <option value="christian">Christian</option> <option value="buddhist">Buddhist</option> <option value="other">Other</option> </select> 

Here is the problem I'm getting on https://validator.w3.org/nu :

The first child option element of a select element with a required attribute, and without a multiple attribute, and without a size attribute whose value is greater than 1, must have either an empty value attribute, or must have no text content. Consider either adding a placeholder option label, or adding a size attribute with a value equal to the number of option elements.

name tag is missing for your select option

Also, the select option should have value=""

<Label for="religion">Select Your Religion</Label>
<select required name="religion" class="form-control" id="religion">
   <option value="">Select Your Religion</option>
   <option value="hindu">Hindu</option>
   <option value="muslim">Muslim</option>
   <option value="christian">Christian</option>
   <option value="buddhist">Buddhist</option>
   <option value="other">Other</option>
</select>

Like the validator message says

...must have either an empty value attribute, or must have no text content...

Make sure your option has an empty value, like <option disabled value="">

 <Label for="religion">Select Your Religion</Label> <select required class="form-control" id="religion"> <option disabled value="">Select Your Religion</option> <option value="hindu">Hindu</option> <option value="muslim">Muslim</option> <option value="christian">Christian</option> <option value="buddhist">Buddhist</option> <option value="other">Other</option> </select> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM