Ok, so from what I found googling around, I can do something like (please correct me if I’m wrong):
component.options[component.selectedIndex].defaultSelected = true;
But what if I want to change it afterwards? I mean if I do the same action on a different option, will both have defaultSelected to true? Do I need to first go trough all the options and set defaultSelected = false and only after do a re-assigning?
Also is there a easy way to get the defaultSelected option rather than go trough all the options in a loop and return when defaultSelected = true is reached?
Regards,
Bogdan
More than one option can have its deftaultSelected property set to true. If you don’t know which ones have the defaultSelected property set and you wish to change it, you must iterate over all of them and set the the one you want to be the default to true and the others to false.
However, there is rarely a need to do so. The defaultSelected property is only used when a form is reset to determine which option will be selected by default. If some other option is selected, it will become the selected option and the default selected option is no longer of interest.
Setting the default option after the document has loaded does not, of itself, change the option that is selected.