| Author |
how to access combo-box value in javascript?
|
Pras Tiwari
Ranch Hand
Joined: Nov 07, 2005
Posts: 185
|
|
Hi, 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
|
|
<html> <head> <title></title> <script> function doChange(objSelect) { alert(objSelect.value); } </script> </head> <body> <select onchange="doChange(this);" name="mySelect"> <option value="1">One</option> <option value="2">Two</option> </select> </body> </html>
|
 |
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> </html:select> </html:form>
|
SCJP5
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
Prashant, 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.
|
Merrill
Consultant, Sima Solutions
|
 |
 |
|
|
subject: how to access combo-box value in javascript?
|
|
|