• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to get value from combo box

 
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello List[],

i want to display selected value in the combo box using struts.when i select combo box it should display its select value in jsp page;Please help me.

Thanks
MyJsp page look like this.

<%@ page language="java" pageEncoding="ISO-8859-1" import="java.util.*" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>

<html>
<head>
<title>JSP for SimpleForm form</title>
</head>
<script language="Javascript">
function sel_click()
{
var f = document.modcat;
var i=f.cat.selectedIndex;
var str=f.cat.options[i].text;
document.modcat.vr_cat.value=str;
document.modcat.cat_val.value=document.modcat.elements[0].value;
}
</script>
<body>
<html:form action="/simple">
name : <html:text property="name"/><html:errors property="name"/><br/>
<html:submit/><html:cancel/>

<html:select property="name" onchange="sel_click();"><html ptionsCollection name="simpleForm" property="smyMonth" value="key" label="value" /></html:select>
<bean:write name="simpleForm" property="name" />

</html:form>
</body>
</html>
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In reality you are off topic here, since what you are asking is a Javascript question. I'll answer the best I can:

You need to add an onchange="" attribute to the select element and then to get the value of the select:

getElementById('myElemId').value

After that you can do what you want with it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic