Welcome to WebmasterWorld Guest from 54.167.0.111

Forum Moderators: open

Message Too Old, No Replies

set seletced value of <select> after its been declared

     

danbhala

10:31 am on Jun 28, 2007 (gmt 0)

5+ Year Member



hi,

does anyone know if you can set the selected value of a <select> after its been declared?

<form name="myForm" action="somewhere">
<select name="test">
<option value='0'>--- Select your Option ---
<option value="1">Option 1
<option value="2">Option 2
<option value="3">Option 3
</select>
</form>

<insert clever javascript here to set that form's selected value to the option with value 2 for example> :)

cheers for the help if you help!

Marshall

10:44 am on Jun 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



danbhala,

Are you talking about an alternate say dropdown box appearing when one of the options is selected giving the user a second option, or merely changing the submitted value results. I'm confused :{

Marshall

abacuss

10:55 am on Jun 28, 2007 (gmt 0)

5+ Year Member



Are you talking of changing the run time accepted value or something else.

Fotiman

3:32 pm on Jun 28, 2007 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



<form name="myForm" action="somewhere">
<select name="test" id="mySelect">
<option value='0'>--- Select your Option ---
<option value="1">Option 1
<option value="2">Option 2
<option value="3">Option 3
</select>
</form>

<script type="text/javascript">
window.onload = function() {
// Select the 3rd item in the list (index begins with zero)
document.getElementById("mySelect").selectedIndex = 2;
}
</script>

 

Featured Threads

Hot Threads This Week

Hot Threads This Month