With input of type text the attribute required is available. It is not the case for select inputs. So how to make them required ?
Asked
Active
Viewed 372 times
0
-
check if value is empty.. – Alex Char Jul 23 '14 at 08:22
-
2possible duplicate of http://stackoverflow.com/questions/8287353/does-the-select-element-have-the-required-attribute – Mritunjay Jul 23 '14 at 08:25
-
1What makes you think it is not possible on `select`? According to [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select) it is perfectly possible. – putvande Jul 23 '14 at 08:30
-
See here http://www.w3schools.com/tags/att_select_required.asp Not working on Most browsers, use jquery validate plugin – Pratik Joshi Jul 23 '14 at 08:43
4 Answers
4
<form>
<select required>
<option></option><!--If this is selected require pop up will appear -->
<option>test</option><!--If this is selected form will be submitted -->
</select>
<input type="submit">
</form>

Mike Ante
- 746
- 1
- 6
- 18
3
You can make them required by using html5 attribute required just like below.
<select required>
<option value="">select an option</option>
<option value="value1">Value 1</option>
<option value="value2">Value 2</option>
</select>
View Example in jsfiddle http://jsfiddle.net/88rXX/

Ajesh VC
- 635
- 5
- 13
1
Set a default value then on form submission check to see if that default value has changed.
If you're using the JQuery validation plug-in, try this Validate select box
You do have to remember though that just because it's validated client side, doesn't mean you shouldn't also check server side.

Community
- 1
- 1

Dark Hippo
- 1,255
- 2
- 15
- 35