Hi,
I have following ajax code so here I want to help to edit the code.
I have servlet name is SendInfo.java.
here feaches destination cities and add into Arraylist according destination city selected by dropdownlist listFrom then that Arraylist send back to displayCity.jsp and displayed in second dorpdownlist listTo.
So please help me edit the following code to send selected city and get Arraylist for displaying.
Thanks in advance.
function loadXMLDoc()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
</script>
</head>
<body>
<h2>AJAX</h2>
<div id="myDiv">
<% getsource = (String)request.getAttribute("sndsource");
stmtSelectSource=con.createStatement();
rsSelectSource = stmtSelectSource.executeQuery(sqlSelectSource);
%>
<td><select name="listFrom" id="listFrom" onChange="loadXMLDoc()">
<option>----Select City----</option>
<%while (rsSelectSource.next())
{%>
<option><%=rsSelectSource.getString(1)%></option>
<%}%>
</select>
<%
//stmtSelectDestination=con.createStatement();
//rsSelectDestination = stmtSelectDestination.executeQuery(sqlSelectDestination);
Iterator itrDest = null;
// ArrayList getListDestination = new ArrayList();
if(getsource != null)
{
List getListDestination = (List)request.getAttribute("sndlistDestination");
itrDest = getListDestination.iterator();
}
%>
<td><select name="listTo" id="listTo">
<option>----Select City----</option>
<%
if(getsource != null)
{
while (itrDest.hasNext())
{%>
<option><%=itrDest.next()%></option>
<%}
} %>
</select>
</div>
</body>
</html>