Forum Moderators: open

Message Too Old, No Replies

Form select tag

Default explanatory text

         

qmeister

4:02 pm on Aug 12, 2009 (gmt 0)

10+ Year Member



Hi,

I have several options available for selection within a form, but I would like an explanatory piece of text "Please select" to be the default text visible (though not selectable). I'm not sure how to achieve this. Can anyone please help ?

Many thanks

My code so far:-

<select name="treatment" size="1" >

<option value="service1" selected="selected">service1</option>
<option value="service2">service2</option>
<option value="service3">service3</option>
<option value="service4">service4</option>
</select>

incrediBILL

6:33 pm on Aug 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Normally this is accomplished with javascript validation during the submit process.

Since "Please Select" is always the first item on any list, when you validate the form if there are any lists that default to the first item you generate an alert for the user and abort the form submission.

Of course you will still need to validate the same form server side because anyone with javascript disabled, which is a growing trend due to malware, will be able to submit your form with the defaults of "Please Select" intact.