Instead of Ajax call we can populate States based on country using javascript in struts1.3
RegisterUser.jsp:-
Its normal Jsp, in the form i have two select fields in Form. Country and State.
Country:<html:select property="region" styleId="region" onchange="getTerritories(this.form, this.value);">
<html:option value="">-- None --</html:option>
<html:option value="Central">Central</html:option>
<html:option value="East">East</html:option>
<html:option value="Enterprise">Enterprise</html:option>
<html:option value="West">West</html:option>
</html:select>
State:<html:select property="territory" styleId="territory" >
<html:option value="">-- Please Select --</html:option>
</html:select>
"getTerritories" is the javascript funtion that calls when onChange Event occurs.
required JS File:-
var territories=new Array();
territories.Central=new Array("North Central","Great Lakes","Great Plains");
territories.East=new Array("Mid-Atlantic","NY NJ Metro","WallStreet","South","Upstate NY/NE");
territories.Enterprise=new Array("IBM-TBD","SAP-TBD","Healthcare-TBD","Automotive-TBD","CSC","Accenture","IBM","Ford","Delphi Automotive","Target");
territories.West=new Array("Pacific NW","Pacific SW","South West");
function getTerritories(form,index){
var cntrySel=document.getElementById("region");
// alert("cntrySel"+cntrySel.value);
terrirotyList=territories[cntrySel.value];
if(terrirotyList!=null){
setTerritories("territory",terrirotyList,terrirotyList);
}
}
function setTerritories(fieldId,newOptions,newValues){
// alert(fieldId+"@@"+newOptions+"&&"+newValues);
var selectedField=document.getElementById("territory");
selectedField.options.length=0;
for(i=0; i<newOptions.length;i++){
selectedField.options[selectedField.length]=new Option(newOptions[i],newValues[i]);
}
}