So I have something like this: <select name="" id="theid"> <option value="1">Text</option> <option value="2">Something</option> </select> Code (markup): Obviously, by default the list is set to "Text", however, when I click a button, I want it to change to "Something". How? Thanks, BP
<select name="" id="theid"> <option value="1">Text</option> <option value="2">Something</option> </select> <input type="button" onclick="document.getElementById('theid').options[1].selected = true;" value="Button" /> Code (markup): ?
Hmmm. Not really. Because I have created a PHP/MySQL backend, which generates the ids - and if you delete a row, you will end up with uneven numbers. For example, my current select is like: <select name="" id="theid"> <option value="1">Text</option> <option value="2">Something</option> <option value="8">Something Else</option> </select> Code (markup): And because of the way it works, if I want "Something Else" to be selected. I have to pass the value "8" through it somewhere. I am not adverse to using id="8" or name="8" if it will help solve my problem.
Well, you need to have a criteria/identifier to be able to select an option item. So you must use either "value" or "text" or index as criteria. I'm sorry, but i don't understand what you exactly want, are you talking about selecting an item "server side" or "client side"? Since we are in JS Forum, i suppose you mean client side, so usualy you would just loop through all option items and then select the item which matches specific criteria.
Well this seems to be a bit of a pickle then. And yeah, I mean client side. So say I have <option value="2" id="Something">Something</option> is their anyway to do it like that? The server outputs the value as the ID set in the MySQL database (auto increment), so when you add a few things, then delete them, the next time you add something the value will be much higher. At the moment, I use Ajax to retrieve the id from the database, and it has to change the select value to the corresponding word value. Thanks a lot, BP