Welcome to WebmasterWorld Guest from 184.72.177.182

Forum Moderators: open

Message Too Old, No Replies

set seletced value of <select> after its been declared

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

New User

5+ Year Member

joined:Mar 23, 2007
posts:13
votes: 0


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!

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

Senior Member from US 

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 4, 2001
posts: 2143
votes: 7


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

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

Junior Member

10+ Year Member

joined:Dec 29, 2005
posts:140
votes: 0


Are you talking of changing the run time accepted value or something else.
3:32 pm on June 28, 2007 (gmt 0)

Senior Member from US 

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

joined:Oct 17, 2005
posts:4965
votes: 10


<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>

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members