This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Selecting value in select tag