<select id="stateSelect" name="selectedState" onchange="loadCities(this.value)"> <s:iterator value="#session['myModel'].states" status="itr"> <option value="<s:property value="code"/>"> <s:property value="label"/> </option> </s:iterator> </select> <select id="citySelect" name="selectedCity" > </select>
JQuery
function loadCities(value){ $("#citySelect").get(0).options.length = 0; $("#citySelect").get(0).options[0] = new Option("Loading cities", "-1"); $.ajax({ type: "POST", url: "MyStrutsActionToGetCities", data: "{stateID:" + value+ "}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { $("#citySelect").get(0).options.length = 0; $("#citySelect").get(0).options[0] = new Option("Select city", "-1"); $.each(msg.d, function(index, item) { $("#citySelect").get(0).options[$("#citySelect").get(0).options.length] = new Option(item.Display, item.Value); }); }, error: function() { $("#citySelect").get(0).options.length = 0; alert("Failed to load cities"); } }); }
Taken from this tutorial
Refresh . This example is used to load a list of cities based on the selected state. You can do this to download a list of states of your choice of country. Also here is a link describing ajax request / response for struts without using any plugin
anu
source share