
Hi everyone!!! I want to create an application for internal portal. here i have to create one dropdown listbox to select single elemnt using AJAX control . But i don't know anything about AJAX. In that listbox,listbox items are dictly fetched from databases tables. and i want to select only one item and save that selected in session to use that in further use.
Please, your suggestios and example codes are valuable to me. Thank you for your reply in advance.

Hello Friend,
Try the following code:
1)ajaxlist.jsp:
<%@page import="java.sql.*"%>
<html>
<head>
<script language="javascript" type="text/javascript">
var xmlHttp
var xmlHttp
function showState(){
if (typeof XMLHttpRequest != "undefined"){
xmlHttp= new XMLHttpRequest();
}
else if (window.ActiveXObject){
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttp==null){
alert ("Browser does not support XMLHTTP Request")
return
}
var url="getlist.jsp";
xmlHttp.onreadystatechange = stateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function stateChange(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("country").innerHTML=xmlHttp.responseText;
}
}
function hello(){
var comboValue
var selIndex =document.getElementById('sel').selectedIndex;
comboValue = document.getElementById('sel').options[selIndex].value;
alert(comboValue);
}
</script>
</head>
<body onLoad="showState();">
<br>
<form name="form">
<div id='country'>
</div>
</form>
</body>
</html>
2)getlist.jsp:
<%@page language="java" import ="java.sql.*" %>
<%
String buffer="<select id='sel' onchange='hello();'>";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from country");
while(rs.next()){
buffer=buffer+"<option value='"+rs.getString(2)+"'>"+rs.getString(2)+"</option>";
}
buffer=buffer+"</select>";
response.getWriter().println(buffer);
%>
Thanks

Thank you for your reply. But for example, we we type letter "A" in google.com brower, it gives all probable list starting from letter "A" from databases.
Like same, when i type any letter , it should show all country names in drop-down manner in list-box. And if i will not type any letter , it gives me entire list from database (stored in Mysql).
And I am not able to get selected name. I have tried using
print("code sample");
<% String abc=request.getparameter("sel"); System.out.println("selected field is :: "+abc); %>
Please, help me..Thank you for your reply in advance.