Ядро Ajax для комбинированного поля страны и страны, которое будет использоваться в JSP.Ajax для сотового поля страны и страны
0
A
ответ
0
ajaxTest.jsp
<%@page contentType="text/html" pageEncoding="UTF-8" import="com.test.AjaxClass.*"%>
AJAX Страница
var XmlHttp=false;
function CreateXmlHttp()
{
try
{
XmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); //for IE6
}
catch(e)
{
try
{
XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(oc)
{
XmlHttp = new XMLHttpRequest();//for browser mozila, opera, firefox.
}
}
}
function cState(){
var countid = document.getElementById('country').value;
CreateXmlHttp();
XmlHttp.onreadystatechange=HandleResponse;
XmlHttp.open("GET", "any.jsp?r=Math.random()&countid="+countid, true);
XmlHttp.send(null);
}
function HandleResponse(){
var stateobj = document.getElementById("state");
stateobj.options.length = 0;
if(XmlHttp.readyState==4 || XmlHttp.readyState=="complete"){
var XmlRoot = XmlHttp.responseXML.documentElement;
var xRows = XmlRoot.getElementsByTagName("check");
for(var i=0; i<xRows.length; i++){
var stateid = xRows[i].childNodes[0].firstChild.nodeValue;
var statename = xRows[i].childNodes[1].firstChild.nodeValue;
stateobj.options[i] = new Option(statename,stateid);
}
}
}
</script>
</head>
<body>
<select onchange="cState();" name="country" id="country">
<option value="0">Select Country</option>
<%
for (CountryClass cc : ajax.getCoutryList()) {
%>
<option value="<%=cc.getCountryid()%>"><%=cc.getCountryName()%></option>
<% }
%>
</select>
<select name="state" id="state">
</select>
</body>
any.jsp
<?xml version="1.0"?>
<% @ страница CONTENTTYPE = "текст/XML" pageEncoding = "UTF-8" импорт = "com.test.AjaxClass. *" %> <% int countid = Integer.parseInt (request.getParameter ("countid")); //System.out.println("tt :: "+ countid); java.util.List statelist = call.changeState (countid); //System.out.println("length :: "+ statelist.size()); для (StateClass SC: statelist) { %> <% = sc.getStateid()%> <% = sc.getStateName()%> <% } %>
AjaxClass .java
package com.test;
импорт java.util.ArrayList; import java.util.List;
общественного класса AjaxClass {
private List<CountryClass> coutryList = new ArrayList<CountryClass>();
public List<CountryClass> getCoutryList() {
coutryList.add(new CountryClass(1, "India"));
coutryList.add(new CountryClass(2, "Pakistan"));
coutryList.add(new CountryClass(3, "Bangladesh"));
coutryList.add(new CountryClass(4, "U.A.E."));
return coutryList;
}
public void setCoutryList(List<CountryClass> coutryList) {
this.coutryList = coutryList;
}
public class CountryClass {
public Integer countryid;
public String countryName;
public String getCountryName() {
return countryName;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
public Integer getCountryid() {
return countryid;
}
public void setCountryid(Integer countryid) {
this.countryid = countryid;
}
public CountryClass(Integer countryid, String countryName) {
this.countryid = countryid;
this.countryName = countryName;
}
}
private List<StateClass> stateList = new ArrayList<StateClass>();
public List<StateClass> getStateList() {
stateList.add(new StateClass(1, 1, "Gujarat"));
stateList.add(new StateClass(2, 1, "Maharashtra"));
stateList.add(new StateClass(3, 2, "Karachi"));
stateList.add(new StateClass(4, 2, "Lahore"));
stateList.add(new StateClass(5, 3, "Dhaka"));
stateList.add(new StateClass(6, 3, "Chittagong"));
stateList.add(new StateClass(7, 4, "Dubai"));
stateList.add(new StateClass(8, 4, "Behrin"));
stateList.add(new StateClass(9, 4, "Sarjah"));
return stateList;
}
public void setStateList(List<StateClass> stateList) {
this.stateList = stateList;
}
public class StateClass {
Integer stateid;
Integer countryref;
String stateName;
public Integer getCountryref() {
return countryref;
}
public void setCountryref(Integer countryref) {
this.countryref = countryref;
}
public String getStateName() {
return stateName;
}
public void setStateName(String stateName) {
this.stateName = stateName;
}
public Integer getStateid() {
return stateid;
}
public void setStateid(Integer stateid) {
this.stateid = stateid;
}
public StateClass(Integer stateid, Integer countryref, String stateName) {
this.stateid = stateid;
this.countryref = countryref;
this.stateName = stateName;
}
}
public List<StateClass> changeState(Integer countryref) {
List<StateClass> newList = new ArrayList<AjaxClass.StateClass>();
for (StateClass stateClass : getStateList()) {
if (stateClass.countryref == countryref) {
newList.add(stateClass);
}
}
return newList;
}
}
Смежные вопросы
- 1. Джанго-страны и TastyPie: Получить название страны
- 2. ISO Данные страны/страны
- 3. разница между [границы @ страны] и [границы/@ страны]
- 4. libphonenumber ios получить код страны для страны
- 5. Язык Android для страны Код страны Код
- 6. название страны - возврат код страны
- 7. Получить название страны и временную метку для текущей страны
- 8. NSLocale и название страны
- 9. Magento: Получить код страны по названию страны
- 10. Преобразовать код страны в название страны
- 11. страны группироваться и сосчитать
- 12. География страны и города?
- 13. Сценарий для определения страны
- 14. Код страны для Филиппин
- 15. Сохранить код страны и адрес
- 16. C#: Получить название страны из кода страны
- 17. Получить код страны и страны (ISO 639-1)
- 18. Все страны Страны Города и Почтовые индексы в приложении
- 19. выпадающих списков с кодом страны и флаги страны
- 20. Как получить код страны и название страны, используя IP
- 21. Как получить коды названия страны и страны (ISD) в Spinner
- 22. Получить код страны и страны с javascript (на стороне клиента)
- 23. HTML выберите выпадающие страны и страны, использующие (countries.js)
- 24. Ресурс Android - массив для хранения имени страны/кода страны
- 25. Как предсказать правильное название страны для имени страны?
- 26. Разрешить выбор страны и масштаба только на уровне страны
- 27. Страны типа поля получить Null в Symfony2
- 28. Сопоставьте код страны двух букв с предопределенным массивом кода страны
- 29. Как получить название страны из страны Id in angularjs
- 30. Аякса государственного города страны
ли вы сказать, пожалуйста? – RPM1984
Связано: http://stackoverflow.com/questions/2263996/populating-child-dropdownlists-in-jsp-servlet Кстати, поле со списком ** не ** так же, как выпадающее меню! Выпадающий список со списком *. Вы не хотите иметь поле со списком здесь. – BalusC