Thanks for your prompt replies, guys.
rnd_me, I can’t use optgroup because this won’t show up in the default (collapsed) state of the select element, only if you actually open the drop down.
Fumigator, I haven’t quite understood what you mean but basically I am
using the “select one” method, only that the initial option doesn’t read “select one” but “Label text”.
Maybe I didn’t quite express myself clearly, it’s confusing, I know. So, to rephrase my problem:
I have a search form on a page that, when submitted, shows some search results and itself again.
If no option in a select has a
automatically the one that is shown by default because I’m adding it after the DOM has been established, and the originally selected first option stays being selected even if it becomes the second one now. This is why I’m setting the selected state of the new option to “selected”.
When someone makes a choice (e. g. option three) and submits the form, it would display the search results and the form again, and it’s supposed to display option three as selected (by setting a hard coded
attribtue via PHP). However, as jQuery is prepending an option and setting its state to “selected” it actively removes the selected state from the third item. So I kinda need to find out if there is a hard coded
attribute and don’t make the dynamically added item selected in that case. How would I do that?
I hope I haven’t scared you away now with my lengthy and complicated description. Unfortunately I can’t currently show you a working example.