Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Struts
Search Coderanch
Advance search
Google search
Register / Login
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
Tim Cooke
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Struts
Dependent drop down boxes with javascript?
karthik ekantha
Ranch Hand
Posts: 78
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I am new to
Struts
. I need to implement dependent drop down boxes.
it's not working for Dependent drop down boxes 2nd state drop box is not properly working ..
2nd drop down box not orderly displayed ...
please help any one
<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> <%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> <html> <head> <title></title> <script> function submitform() { var forms = document.getElementsByTagName('form'); for ( var formIndex = 0; formIndex < forms.length; formIndex++) { forms[formIndex].submit(); } } </script> <head> <html:form action="/country"> Select Country: <html:select name="CountryForm" property="country" onchange="submitform()"> <html:option value="0">--Select Country--</html:option> <html:optionsCollection name="CountryForm" property="countryList" label="countryname" value="countryid" /> </html:select> </br> Select state: <html:select name="CountryForm" property="state" onchange="submitform()"> <html:option value="0">--Select Country--</html:option> <html:optionsCollection name="CountryForm" property="stateList" label="label" value="value" /> </html:select> <html:submit value="save" property="method" /> <html:reset value="Reset" /> </html:form> </body> </html>
public class CountryAction extends Action { private final static String SUCCESS = "success"; public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { CountryForm formBean=(CountryForm)form; ArrayList<country> countrylist=new ArrayList<country>(); countrylist.add(new country("1","INDIA")); countrylist.add(new country("2","USA")); countrylist.add(new country("3","UK")); countrylist.add(new country("4","AUSTRALIA")); formBean.setCountry(""); formBean.setCountryList(countrylist); ArrayList<LabelValueBean> statelist=new ArrayList<LabelValueBean>(); statelist.add(new LabelValueBean("chennnai", "1")); statelist.add(new LabelValueBean("columbia", "2")); statelist.add(new LabelValueBean("london", "3")); statelist.add(new LabelValueBean("sydney", "4")); formBean.setState(""); formBean.setStateList(statelist); return mapping.findForward(SUCCESS); } public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { return mapping.findForward(SUCCESS); } }
Joe Ess
Bartender
Posts: 9626
16
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Your javascript code submits the form. It doesn't make the second select dependent on the first.
Struts 2 has a
doubleselect
tag. If you aren't maintaining legacy code, I'd recommend you use Struts 2. It is much easier to work with than Struts 1.x.
[
How To Ask Questions On JavaRanch
]
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
please help "javax.servlet.jsp.JspException: Failed to obtain specified collection"
JspException: Failed to obtain specified collection for Struts:optionscollection
Cannot find bean in any scope
Submitting hidden values on the form with onSelect option
Problem with Struts html:select
More...