sending a selected value from a dropdownlist to a servlet with xhr
- by kawtousse
I am trying to send the clicked value of a dropdown list to my servlet to run a SQL query using the value received. To do it I am using Ajax like that:
function showProject(prj) {
xmlhttp = GetXmlHttpObject();
if (xmlhttp == null) {
alert ("Browser does not support HTTP Request");
return;
}
var url = "ServletxmlGenerator.java";
idprj = prj.options[prj.selectedIndex].value;
url = url + "?idprj=" + idprj;
xmlhttp.onreadystatechange = stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
The servlet when
String projectcode=(String) request.getParameter("idprj");
returns null.
When I select a value from the JSP that construct the dropdown list and from which the function showProject is handled the same thing is happned. It returns always null. So the parameter(idprj) is not passed anyway. How can I handle with this. I need to send the selected value to the servlet to run my SQL query.