i have a jsp in which i have select tag and i want to get the and the value selected from the select in jsp in my Servlet
<select id="listoffood" name="dropdown" onchange="foodname();">
<option value="bg">Burger</option>
<option value="pas">pasta</option>
<option value="pi">pizza</option>
</select>
<div id='content'></div>
here is the javascript code
function foodname()
{
var xmlHttpReq = false;
var self = this;
document.getElementById('content').innerHtml='';
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('GET', "InformationServlet", true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.send(null);
self.xmlHttpReq.onreadystatechange= function ()
{
//alert(document.getElementById('content'));
if (self.xmlHttpReq.readyState==4)
{
if (self.xmlHttpReq.status == 200)
{
document.getElementById('content').innerHTML=self.xmlHttpReq.responseText;
}
}
};
}
What i have done is used a get Attribute like this but it aint working its showing null
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// TODO Auto-generated method stub
String coun = request.getParameter("dropdown");
PrintWriter out=response.getWriter();
System.out.println("here : "+coun);
}
Thanks in advance and any piece of code is highly appreciated.