File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes how to access combo-box value in javascript? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to access combo-box value in javascript?" Watch "how to access combo-box value in javascript?" New topic

how to access combo-box value in javascript?

Pras Tiwari
Ranch Hand

Joined: Nov 07, 2005
Posts: 186
In my struts application inside my JSP page I am populating my select-box html:select using collection object in my form-bean. Now on onChange event of my selection-box I want to call javascript function & inside that javascript I want to display value of selected item from combo-box. How to do this?

********Deserve Before You Desire********
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181

function doChange(objSelect) {


<select onchange="doChange(this);" name="mySelect">
<option value="1">One</option>
<option value="2">Two</option>

Shilpa Tendulkar
Ranch Hand

Joined: Jul 29, 2001
Posts: 75
<script language="text/javascript">
function findValue(frmObj){
myvalue = frmObj.form.myValues.options[frmObj.form.myValues.selectedIndex].value;
<html:form action="someaction">
<html:select property="myValues" name="MyActionBean" onchange="findValue(this);form.submit();">
<html ption value="1">1</html ption>
<html ption value="2">2</html ption>

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864

In case you're confused by the two different approaches proposed by Dom and Shilpa, here's my two cents:

Both Dom's solution and Shilpa's solution work great as long as you know you have options that specify a value:

<option value="1">my option</option>

If you have options that do not specify a value as in:

<option>my option</option>

Only Shipla's solution works.

Note to Shilpa:

Thanks for the input. I hope you keep participating and contributing.

However, Java Ranch rules indicate you need two names (first and Last) for your display name. Please make sure the "publicly displayed name" in your profile meets the JavaRanch naming policy.

Consultant, Sima Solutions
I agree. Here's the link:
subject: how to access combo-box value in javascript?
It's not a secret anymore!