In a form i have a selectbox. The selectable items of that selectbox are feeded from a database.
Now i want that the very first entry show e.g. a “Please choose:”
But if i put this between the <option> tag it gives me an error when submitting the form,
since there is no item “Please choose:”, i.e. i have to make this entry not selectable.
Can anybody give me a hint how to handle this?
You will need to implement some sort of form validation to check that a valid option is selected. And stop the form from submitting if it is.
There are plenty of javascript validation scripts at javascriptsource.com and if you are using php you can find some pointers in the following thread http://www.sitepoint.com/forums/showthread.php?t=166446
hmmm, isn’t there any JavaScript free solution for this?
My page is and should remain JavaScript free.
What about php? Are you using that?
Otherwise, you could always get rid of the “please choose” option.
put disabled=“disabled” in the option tag…
thanks Sketch, that’s what i was looking for.
I’ve read about that some time ago and couldn’t remember.
If “Please choose” isn’t really an option, then it should be a label:
<select name="myselect">
<optgroup label="Please choose:">
<option>1</option>
<!--lather, rinse, repeat-->
</optgroup>
</select>
This will keep the “Please choose” text from being selectable, since it’s not an option :).
Good point, i’ll check this.
I’ve read about this, but in a combination of multiple labels, i.e. grouping together option which belong together and braking it down in groups.
So my thought was that this doesn’t match my requirements.
Well, that’s the problem with thinking. I should leave it to the horses, they have a bigger head 