开发者

Default entry for Selectbox but not present in list

开发者 https://www.devze.com 2022-12-13 16:18 出处:网络
Is it possible to have a selectbox that has a default option such as: \"Select One\" but have the term \"Select One\" not present in the actual list itself?

Is it possible to have a selectbox that has a default option such as: "Select One" but have the term "Select One" not present in the actual list itself?

 <select name="test" id="test">
 <option value="" selected="selected">Select A Entry</option>
 <optgroup label="A Label">
    <option value="one">Op开发者_开发问答tion 1</option>
    <option value="two">Option 2</option>
    <option value="three">Option 3</option>
 </optgroup>

    </select>


I would go so far as to say no. Personally I would leave it in this list but write a javascript function to validate user input on form submission.


You could use this little bit of Javascript to do the trick:

<select name="test" id="test" onclick="this.remove(0);this.onclick=''">

As they click the list to select an option, it removes the first option ("Select an Entry" from the list, then clears the event handler so it only does this the first time.

0

精彩评论

暂无评论...
验证码 换一张
取 消