struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "chiji nwankwo" <cn...@hotmail.com>
Subject Re: struts selection and Javascript onchange question
Date Wed, 29 Aug 2001 10:13:49 GMT
<html><div style='background-color:'><DIV>
<P>Hi,</P>
<P>I had a similar problem and tried to find the best way to handle the problem, without
mixing&nbsp; JavaScript and&nbsp;jsp syntax.&nbsp; What I came up with was a series
of&nbsp;select boxes, some of&nbsp;which were dependant on others,&nbsp;that changed
their values based on&nbsp;the selection made in a different select box.&nbsp;&nbsp;I
have&nbsp;a series of select boxes that&nbsp;call the submit method&nbsp;everytime
a change is made.&nbsp; Calling the submit method in the onchange event handler, means
that the form posts itself every time selection is made.&nbsp;&nbsp;I can then track
which of the&nbsp;select boxes was changed, read the new value, which has just been submitted
and populate the other lists based on the newly changed&nbsp;value.&nbsp; This is
an example of what I mean.</P>
<P>Within jsp page.</P>
<P><EM>&lt;html:form action="/archive.do"&gt;&nbsp;<BR>&nbsp;&nbsp;&nbsp;
&lt;bean:message key="select.title.seasons" /&gt;<BR>&nbsp;&nbsp;&nbsp;
&lt;html:select property="season" onchange="submit()"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;html:options property="value" collection="seasonsList" /&gt;<BR>&nbsp;&nbsp;&nbsp;
&lt;/html:select&gt;&lt;br/&gt;&lt;br/&gt;&nbsp;</EM><EM>&nbsp;&nbsp;
</EM></P>
<P><EM>&nbsp;&nbsp;&nbsp;&lt;html:hidden property="option" value="season"
/&gt;<BR>&nbsp;&nbsp; &lt;html:hidden property="action" value="Populate"
/&gt;<BR>&lt;/html:form&gt;&nbsp;&nbsp;<BR></EM>&nbsp;<BR><EM>&nbsp;&lt;html:form
action="/archive.do"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;bean:message
key="select.title.oppositions" /&gt;<BR>&nbsp;&nbsp; &nbsp;&nbsp;&lt;html:select
property="opposition" onchange="submit()"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;html:options property="value" collection="oppositionsList" /&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/html:select&gt;&lt;br/&gt;&lt;br/&gt;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;html:hidden
property="option" value="opposition" /&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;
&lt;html:hidden property="action" value="Populate" /&gt;<BR>&nbsp;&lt;/html:form&gt;&nbsp;</EM></P>
<P>Within perform method:</P>
<P><EM>String action = &lt;form instance&gt;.getAction();&nbsp;&nbsp;
// action set by hidden variable in jsp page</EM></P>
<P><EM>String option = &lt;form-instance&gt;.getOption(); // option set
by hidden variable in jsp page</EM></P>
<P>if the action is equal to the action specified in the form's hidden variable and
option is equal to option specified in the forms hidden variable, then retrieve the selected
value of the first select box and populate the arrayList of options for the second select
box.</P>
<P>I hope this makes sense.</P>
<P>Chiji.</P>
<P>&nbsp;</P>
<DIV></DIV>
<DIV></DIV>
<P>&gt;From: Robin Whitley <RWHITLEY@SILVERSTREAM.COM></P></DIV>
<DIV></DIV>&gt;Reply-To: struts-user@jakarta.apache.org 
<DIV></DIV>&gt;To: "'struts-user@jakarta.apache.org'" <STRUTS-USER@JAKARTA.APACHE.ORG>
<DIV></DIV>&gt;Subject: struts selection and Javascript onchange question

<DIV></DIV>&gt;Date: Tue, 28 Aug 2001 23:25:50 -0400 
<DIV></DIV>&gt;MIME-Version: 1.0 
<DIV></DIV>&gt;Received: from [64.125.133.20] by hotmail.com (3.2) with ESMTP
id MHotMailBD55ABD5004540043217407D85140B790; Tue, 28 Aug 2001 20:26:13 -0700 
<DIV></DIV>&gt;Received: (qmail 11536 invoked by uid 500); 29 Aug 2001 03:24:58
-0000 
<DIV></DIV>&gt;Received: (qmail 11524 invoked from network); 29 Aug 2001 03:24:58
-0000 
<DIV></DIV>&gt;Received: from greensboro.bondisoftware.com (216.54.174.133)
by daedalus.apache.org with SMTP; 29 Aug 2001 03:24:58 -0000 
<DIV></DIV>&gt;Received: by COSMO with Internet Mail Service (5.5.2653.19)id
<RZZ50VDZ>; Tue, 28 Aug 2001 23:25:51 -0400 
<DIV></DIV>&gt;From struts-user-return-16241-cn081 Tue, 28 Aug 2001 20:27:23
-0700 
<DIV></DIV>&gt;Mailing-List: contact struts-user-help@jakarta.apache.org;
run by ezmlm 
<DIV></DIV>&gt;Precedence: bulk 
<DIV></DIV>&gt;list-help: <?xml:namespace prefix = mailto /><mailto:struts-user-help@jakarta.apache.org>
<DIV></DIV>&gt;list-unsubscribe: <mailto:struts-user-unsubscribe@jakarta.apache.org>
<DIV></DIV>&gt;list-post: <mailto:struts-user@jakarta.apache.org>
<DIV></DIV>&gt;Delivered-To: mailing list struts-user@jakarta.apache.org 
<DIV></DIV>&gt;Message-ID: &lt;3125D8065A0AD411A90A009027B11742058942@COSMO&gt;

<DIV></DIV>&gt;X-Mailer: Internet Mail Service (5.5.2653.19) 
<DIV></DIV>&gt;X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;I have a form that has a selection box for country. If "UNITED
STATES" is 
<DIV></DIV>&gt;selected, the form has a stateProvince selection box that should
be 
<DIV></DIV>&gt;populated with "state" options. If "CANADA" is selected, the
stateProvince 
<DIV></DIV>&gt;selection box should be populated with the "province" options.
I use 
<DIV></DIV>&gt;struts_logic:equal based on the "country" bean property 
<DIV></DIV>&gt;to accomplish this. The form populates the struts_html:options
from a 
<DIV></DIV>&gt;collection. The logic works properly if there is an initial
value for 
<DIV></DIV>&gt;country. However, when the country option is changed, the onchange
event 
<DIV></DIV>&gt;does not appear to fire the javascript function fillStateProvince.

<DIV></DIV>&gt; 
<DIV></DIV>&gt;What I tried to do in the fillStateProvince function was to
test the 
<DIV></DIV>&gt;selected option for country, and set the value on the bean,
hoping that this 
<DIV></DIV>&gt;would set my struts_html:options properly. My sysouts indicate
that when 
<DIV></DIV>&gt;the form loads, it sets the country value to UNITED STATES
and then to 
<DIV></DIV>&gt;CANDADA, but that when I change country, the function doesn't
fie. 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;I've included the pertinent code. My question, is this the
proper way to 
<DIV></DIV>&gt;handle this or is there a better way to accomplish the same
result. 
<DIV></DIV>&gt;Does anybody see anything silly that I am doing in the Javascript,
or struts 
<DIV></DIV>&gt;logic that is causing this result. 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;Any help would be appreciated. 
<DIV></DIV>&gt; 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;Thanks, 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;Robin Whitley 
<DIV></DIV>&gt; 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;<% -- Javascript -- %> 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;<%@ page language="Java" contentType="text/html; charset=UTF-8"
</DIV>>errorPage="error.jsp" %> 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;<?xml:namespace prefix = jsp /><jsp:useBean class=com.sssw.website.model.User
id=user scope="session"></jsp:useBean> 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;
<SCRIPT language=JavaScript>
</DIV>>
</DIV>><function fillStateProvince(inForm,selected) {
</DIV>>
</DIV>>  if (selected == 'UNITED STATES') {
</DIV>>   <%
</DIV>>	user.setCountry("UNITED STATES");
</DIV>>	System.out.println(" Set Country United States");
</DIV>>   %>
</DIV>>  }
</DIV>>
</DIV>>   if (selected == 'CANADA') {
</DIV>>    <%
</DIV>>	user.setCountry("CANADA");
</DIV>>	System.out.println(" Set Country CANADA");
</DIV>>    %>
</DIV>>  }
</DIV>>}
</DIV>>
</DIV>>
</DIV>>
</DIV>></SCRIPT>
 
<DIV></DIV>&gt; 
<DIV></DIV>&gt; 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;<%-- In the form - country -- %> 
<DIV></DIV>&gt;<TD colspan="2"> 
<DIV></DIV>&gt; <?xml:namespace prefix = struts_html /><struts_html:select
property="country" onchange="javascript:&#13;</DIV>>optionsStateProvince(document.userRegistrationForm,document.userRegistration&#13;</DIV>>Form.country.options[document.userRegistrationForm.country.selectedIndex].te&#13;</DIV>>xt)">
<DIV></DIV>&gt; <struts_html:options property="value" DIV < collection="countryOptions">&gt;labelProperty="label"
/&gt; 
<DIV></DIV>&gt; </struts_html:select>
<DIV></DIV>&gt;</TD> 
<DIV></DIV>&gt; 
<DIV></DIV>&gt;<%-- In the form - stateProvince -- %> 
<DIV></DIV>&gt; <TR valign="top">
<DIV></DIV>&gt; <TD class=bodytext width="500">
<DIV></DIV>&gt; <?xml:namespace prefix = struts_bean /><struts_bean:message
key="UserRegistration.stateProvince"></struts_bean:message>
<DIV></DIV>&gt; </TD>
<DIV></DIV>&gt; <?xml:namespace prefix = struts_logic /><struts_logic:equal
scope="session" property="country" DIV < name="user">&gt;value="UNITED STATES"&gt;

<DIV></DIV>&gt; 
<DIV></DIV>&gt; <TD colspan="2" align="left" height="29">
<DIV></DIV>&gt; <struts_html:select property="state">
<DIV></DIV>&gt; <struts_html:options property="value" DIV < collection="stateOptions">&gt;labelProperty="label"
/&gt; 
<DIV></DIV>&gt; </struts_html:select>
<DIV></DIV>&gt; </TD>
<DIV></DIV>&gt; </struts_logic:equal>
<DIV></DIV>&gt; <struts_logic:equal scope="session" property="country"
DIV < name="user">&gt;value="CANADA"&gt; 
<DIV></DIV>&gt; <TD colspan="2" align="left" height="29">
<DIV></DIV>&gt; <struts_html:select property="state">
<DIV></DIV>&gt; <struts_html:options DIV < collection="provinceOptions">&gt;property="value"
labelProperty="label" /&gt; 
<DIV></DIV>&gt; </struts_html:select>
<DIV></DIV>&gt; </TD>
<DIV></DIV>&gt; </struts_logic:equal>
<DIV></DIV>&gt; </TR>
<DIV></DIV></struts_html:options></struts_html:options></struts_html:options></mailto:struts-user@jakarta.apache.org></mailto:struts-user-unsubscribe@jakarta.apache.org></mailto:struts-user-help@jakarta.apache.org></div><br
clear=all><hr>Get your FREE download of MSN Explorer at <a href='http://go.msn.com/bql/hmtag_itl_EN.asp'>http://explorer.msn.com</a><br></html>

Mime
View raw message