I have 2 combobox(select) on html page and i want to populate data in second combobox based on data selected in first combobox by user.I am using jsp and ajax for that.I have Ajax code but i dont know how to return data in combobox from server side jsp page..

Please help me.Give me jsp code.
//////////////////////html file

<html>
<head>
<script src="selectcustomer.js"></script>
</head>
<body>
<form> 
Select a Customer:
<select name="customers" onChange="showCustomer(this.value)" >
  <option value="ALFKI">Alfreds Futterkiste</option>
  <option value="NORTS ">North/South</option>
  <option value="WOLZA">Wolski Zajazd</option> 
</select>
<select name="id" id="id">
 <option value="A">a</option>
<div id="txtHint"></div>
 </select>
</form>
<p>
</p>
</body>
</html>

///////////////////////////ajax file(selectcustomer.js)

var xmlHttp

function showCustomer(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="getinfo.jsp";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

//////////jsp file(getinfo.jsp)[Not working..]

<%String name=(String)request.getParameter("q");
String sid=(String)request.getParameter("sid");
out.print("<option>"+name+"</option>");
out.print("<option>"+sid+"</option>");
%>

////////////////

help me for this jsp file....how can i return data to second combobox

i got solution for that.....
something like that ..it works....

<%String name=(String)request.getParameter("q");
String sid=(String)request.getParameter("sid");
%>
<select name="info">
 <option ><%=name%></option>; 
<option >0</option>;
</select>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.