By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 1,985 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

Retrieve and Set Select Tag Questions

P: 83
I want to know how to retrive and set the selected value of select tag....
I have use this code...
Expand|Select|Wrap|Line Numbers
  1. var Negeri=document.getElementById("State").options[document.getElementById("State").selectedIndex].text;
So any ideas?
Oct 9 '08 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
That's the text of the option rather than the option value. Use the value property to get the value.

A shortcut is to use:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("state").value
for getting the value. To set the value, do you mean to change the value of a particular option, or do you mean changing the selected option to another one?
Oct 9 '08 #2

P: 83
Thanks acoder, Ihave already use the value property but some error get in the way first and I realize after debug the error and change the text property to value.....hah Half my day doin the same thing
Oct 9 '08 #3

acoder
Expert Mod 15k+
P: 16,027
So does that mean your problem's solved?
Oct 9 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.