I have an <input>
of type text
that I want to populate with a value from a database using AJAX.
First, I define my text zone like the following:
<td><input type=text id='st' value=" " name='stname' onclick="donnom();" /></td>
In javascript, I do the following:
xhr5.onreadystatechange = function(){
if(xhr5.readyState == 4 && xhr5.status == 200) {
selects5 = xhr5.responseText;
// On se sert de innerHTML pour rajouter les options a la liste
document.getElementById('st').innerHTML = selects5;
}
};
xhr5.open("POST", "ajaxIDentifier5.jsp", true);
xhr5.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
id = document.getElementById(idIdden).value;
xhr5.send("id=" + id);
In IDentifier5.jsp
, I put the next code:
<%
String id = request.getParameter("id");
System.out.println("idDailyTimeSheet ajaxIDentifier5 as is:" + id);
Session s = null;
Transaction tx;
try {
s = HibernateUtil.currentSession();
tx = s.beginTransaction();
Query query = s.createQuery(
"select from Dailytimesheet dailytimesheet " +
"where dailytimesheet.IdDailyTimeSheet=" + id + " ");
for(Iterator it=query.iterate();it.hasNext();) {
if(it.hasNext()) {
Dailytimesheet object=(Dailytimesheet)it.next();
out.print( "<input type=\"text\" id=\"st1\" value=\"" +
object.getTimeFrom() +
"\" name=\"starting\" onclick=\"donnom()\" ></input>");
}
}
} catch (HibernateException e) {
e.printStackTrace();
}
%>
I want to get only the value in the input type text populated from database, because after that I will be able to change it.