Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  10] [ 2]  / answers: 1 / hits: 16033  / 9 Years ago, tue, april 28, 2015, 12:00:00

I have the following piece of code in a contact form for a site I am designing:



<select id=Category name=Category>
<option value=0 selected=selected disabled>Category</option>
<option value=1>General Info</option>
<option value=2>Booking</option>
<option value=3>Auditions</option>
</select>


I would like set the menu such that the user cannot leave category as the selected option. Is there any way to do this with HTML? If not, how would I do it with JavaScript?



Thank you


More From » html

 Answers
8

When the user click on any option, he can´t return the first one back. But he can submit form without change, then you need to validate via JS.



It's quite simple,



function validate() {
var select = document.getElementById('Category');
return !select.value == 0;
}


And the form in HTML:



<form onsubmit=return validate()>...</form>

[#66845] Monday, April 27, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daquanmilesw

Total Points: 57
Total Questions: 102
Total Answers: 110

Location: Wallis and Futuna
Member since Sat, Aug 6, 2022
2 Years ago
daquanmilesw questions
;