This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes How to retreive value attribute of the html:option tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to retreive value attribute of the html:option tag" Watch "How to retreive value attribute of the html:option tag" New topic
Author

How to retreive value attribute of the html:option tag

Shyam kumar
Ranch Hand

Joined: May 21, 2006
Posts: 146
I have the following select tag:

<html:select property="college" onchange="populateCourse();" >
<html ption value="IPU" >IP University</html ption>
<html ption value="DU">Delhi University</html ption>
<html ption value="GJU">GJU</html ption>
</html:select>

I want to retreive the attribute value of <html ption> tag in populateCourse() javascript. The statement document.getElementById("college").selectedIndex is giving me integer index whereas document.getElementById("college").value is giving me the display value like IP University instead of attribute value IPU

How can i do this?
jeff rusty
Ranch Hand

Joined: Nov 07, 2006
Posts: 109
Naveen ,
can you post the code which you have written in the javascript function populateCourse()and "document.getElementById("college").value" will return only the attribute value and not the text in <html ption> or in normal <option> unless you have tried to retrieve the text like this
"document.getElementById("college").options[0].text".
[ December 03, 2006: Message edited by: prem kamal ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to retreive value attribute of the html:option tag
 
Similar Threads
update html:options
how to fill a combobox with values from objects in an ArrayList...
HTML:SELECT
for loop in select struts tag
Help me regarding select value in html:select...