This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Selecting value in select tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Selecting value in select tag" Watch "Selecting value in select tag" New topic
Author

Selecting value in select tag

Deepa More
Ranch Hand

Joined: May 22, 2006
Posts: 68
In JS, How do I show selected value in <select> tag, if I have value which is to be selected but don't have index.
One way is I have to loop thru options of select tag, check their values.
But Is there any other way to do this?

Thanks
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You are going to have to loop through the options to find it.

Eric
Ryan Asleson
Author
Ranch Hand

Joined: Sep 15, 2005
Posts: 39
If the select tag is a single select tag, can't you just access the select tag's value? I think this will report the value of whatever option is selected.... I think.


Ryan Asleson<br />Co-Author, <a href="http://www.amazon.com/Foundations-Ajax-Foundation-Ryan-Asleson/dp/1590595823/sr=1-1/qid=1158926537/ref=pd_bbs_1/002-7412154-2924860?ie=UTF8&s=books" target="_blank" rel="nofollow">Foundations of Ajax</a> and <a href="http://www.amazon.com/Pro-Ajax-Java-Frameworks/dp/1590596773/ref=sr_11_1/002-7412154-2924860?ie=UTF8" target="_blank" rel="nofollow">Pro Ajax and Java Frameworks</a><br /><a href="http://taconite.sf.net" target="_blank" rel="nofollow">Taconite</a> Lead Developer
Deepa More
Ranch Hand

Joined: May 22, 2006
Posts: 68
Thanks for the replies.
But I am not satisfied with these answers.
If I don't want to loop thru options of select, then is there any other way.

Hi Ryan,
I didn't get what you are trying to tell.
My question was, if I have which option value to be selected at time of page load(not index and don't want to access the value but wants to set the value to be selected), then what?
[ September 25, 2006: Message edited by: Deepa More ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
He is saying set the value directly and see if it works.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Selecting value in select tag
 
Similar Threads
how do get selected value from combobox in html
Struts2 - Select - Ajax
Display tag and Struts multibox tag
Struts2 select default selection
Problem passing parameter with optionsCollection