homepage Welcome to WebmasterWorld Guest from 54.227.67.210
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
set seletced value of <select> after its been declared
danbhala




msg:3381022
 10:31 am on Jun 28, 2007 (gmt 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!

 

Marshall




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

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




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

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

Fotiman




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved