AJAX has retrieved value(using some DB operation)and inserted in text box.while retrieving that values on onClick event of button System.out.println shows null value.i want to retrieve value of "emp" input tag
jsp file code:-
function checksubmit1()
{
document.w1allot.prepare.value=1;
document.w1allot.submit();
}
function showState(area_value)
{
if(document.getElementById("ddlFlat").value!="-1" ||
document.getElementById("emp").value!="")
{
xmlHttp=GetXmlHttpObject()
xmlHttp1=GetXmlHttpObject1()
if (xmlHttp==null || xmlHttp1==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="wl_do.jsp"
var url1="wl_do1.jsp"
url=url+"?area_id="+area_value
url1=url1+"?area_id="+area_value
xmlHttp.onreadystatechange=stateChange
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
xmlHttp1.onreadystatechange=stateChange
xmlHttp1.open("GET",url1,true)
xmlHttp1.send(null)
}
else
{
alert("Please Select Area Name");
}
}
function stateChange()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState==200 &&
xmlHttp1.readyState==4 || xmlHttp1.readyState==200)
{
document.getElementById("ddlFlat").innerHTML=xmlHttp.responseText
document.getElementById("emp").value=xmlHttp1.responseText
//alert(xmlHttp1.responseText);
}
}
function GetXmlHttpObject1()
{
var xmlHttp1=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp1=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp1=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp1=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp1;
}
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;
}
</script>
</head>
<body> <div class="main">
<div class="top">
<jsp:include page="resources/header.jsp" ></jsp:include>
</div><div class="middle">
<div class="content">
<form id="w1allot" name="w1allot" action="w1_allotment.jsp" method="post">
<input type="hidden" name="prepare" value="0" />
<h2 class="itemhead" >Allotment of Flat</h2>
<table border="0" class="tblContent" width="95%" cellpadding="2" cellspacing="0">
<tr>
<th width="20%">Select Area: </th>
<td width="30%"><select name="ddlArea" onchange="showState(this.value)">
<option value="-1" selected>--- Select ---</option>
<option value="<%=area%>"><%=area%> </option>
</select>
</td>
<th width="20%">Select Flat</th>
<td width="30%"><div id="ddlFlat"><select name="ddlFlat">
<option value='-1'>Select Area</option>
</select></div>
</td>
</tr>
</table>
<table border="0" class="tblContent" width="95%" cellpadding="2" cellspacing="0">
<tr>
<th>Employee ID:</th>
<td><div id="emp"><input name="emp" type="number" value readonly>
</input><input type="hidden" name="emp" value></input></div></td>
</tr>
</table>
</form>
<input size="15" class="button" type="submit" value="Submit" name="submit" onclick="javascript:checksubmit1();" />
</div>
</div></body>
</html>
Ajax JSP Code:-
<body>
<%
String area=request.getParameter("area_id");
response.setContentType("text/html");
response.setHeader("Cache-Control","no-cache");
try{
int id=0;
String buffer="",name="",dt="";
Connection con=ConnectionManager.getConnection();
Statement stmt = con.createStatement();
String qry="select Employee_ID,Employee_Name,Date_Application from tblUser where Area='"+area+"' and Date_Application=(select MIN(Date_Application) from tblUser where Area='"+area+"' )";
ResultSet rs = stmt.executeQuery(qry);
while(rs.next()){
id=rs.getInt("Employee_ID");
name=rs.getString(2);
dt=rs.getString("Date_Application");
}
if(id!=0){
buffer="<input size=50 name='emp' value='"+id+"::"+name+"::"+dt+"' readonly></input>";
}else {
buffer="<input size=50 value='No Employee have Applied for this Location' readonly></input>";
}
response.getWriter().println(buffer);
}
catch(Exception e)
{response.getWriter().println(e);
} %> </body>
For my testing purpose when i write
System.out.println(request.getParameter("emp"));
on submit button click event i get null value in console but values is get displayed in JSP main page.