ajax to populate an input type text
- by kawtousse
hi,
I have an input type text that i want to populate it with a value from data base using the ajax technique.
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 .
thanks for help.