struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robin Whitley <rwhit...@silverstream.com>
Subject struts selection and Javascript onchange question
Date Wed, 29 Aug 2001 03:25:50 GMT
I have a form that has a selection box for country.  If "UNITED STATES" is
selected, the form has a stateProvince selection box that should be
populated with "state" options. If "CANADA" is selected, the stateProvince
selection box should be populated with the "province" options.  I use
struts_logic:equal based on the "country" bean property 
to accomplish this. The form populates the struts_html:options from a
collection.  The logic works properly if there is an initial value for
country.  However, when the country option is changed, the onchange event
does not appear to fire the javascript function fillStateProvince.  

What I tried to do in the fillStateProvince function was to test the
selected option for country, and set the value on the bean, hoping that this
would set my struts_html:options properly.  My sysouts indicate that when
the form loads, it sets the country value to UNITED STATES and then to
CANDADA, but that when I change country, the function doesn't fie.

I've included the pertinent code. My question, is this the proper way to
handle this or is there a better way to accomplish the same result.  
Does anybody see anything silly that I am doing in the Javascript, or struts
logic that is causing this result.

Any help would be appreciated.


Thanks,

Robin Whitley


<% -- Javascript -- %>

<%@ page language="Java" contentType="text/html; charset=UTF-8"
errorPage="error.jsp" %>

<jsp:useBean id="user" scope="session" class="com.sssw.website.model.User"/>

<SCRIPT language=JavaScript>

<function fillStateProvince(inForm,selected) {  

 if (selected == 'UNITED STATES') {
  <%
	user.setCountry("UNITED STATES");
	System.out.println(" Set Country United States");
  %>
 }

  if (selected == 'CANADA') {
   <%
	user.setCountry("CANADA");
	System.out.println(" Set Country CANADA");
   %>
 }
}



</SCRIPT>



<%-- In the form - country -- %>
<td colspan=2>
	<struts_html:select onchange="javascript:
optionsStateProvince(document.userRegistrationForm,document.userRegistration
Form.country.options[document.userRegistrationForm.country.selectedIndex].te
xt)" property="country" > 
	<struts_html:options collection="countryOptions" property="value"
labelProperty="label" /> 
	</struts_html:select> 
</td>

<%-- In the form - stateProvince -- %>
 <tr valign="top"> 
    <td width = "500" class="bodytext">
	<struts_bean:message key="UserRegistration.stateProvince" /> 
    </td>
    <struts_logic:equal name="user" scope="session" property="country"
value="UNITED STATES">

	<td colspan=2 height="29" align="left">
	   <struts_html:select property="state" >
	   <struts_html:options collection="stateOptions" property="value"
labelProperty="label" /> 
	   </struts_html:select>
        </td>
    </struts_logic:equal>		
    <struts_logic:equal name="user" scope="session" property="country"
value="CANADA">
        <td colspan=2 height="29" align="left">
 	    <struts_html:select property="state" >
	    <struts_html:options collection="provinceOptions"
property="value" labelProperty="label" /> 
	    </struts_html:select>
	</td>
    </struts_logic:equal>	
  </tr>

Mime
View raw message