How to display values ​​in a text field by extracting these values ​​from a database?

I am doing a database project. I have a webpage where I have 5 text fields. In one of the text fields, when it is in focus, I have to show the user the values ​​present in the database. I know how to extract using javascript and AJAX, but I cannot display the resulting values ​​in a text box. I tried a lot, but could not get it.

Can someone help me with this?

The code is as follows:

function showData(){ xmlHttp=GetXmlHttpObject() var id=document.getElementById("vendor_name").value; var url="ftc_id.jsp"; url=url+"?vendor_name="+id; xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true) xmlHttp.send(null); } function stateChanged(){ if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ var showdata = xmlHttp.responseText; var strar = showdata.split(":"); if(strar.length>1){ var strname = strar[1]; document.getElementById("vendor_address").value= strar[1]; document.getElementById("vendor_contact_no").value= strar[2]; document.getElementById("currency").value= strar[3]; document.getElementById("po_value_rs").value= strar[4]; } 

Map me m using the showData line as above. For autocomplete, I have to make some changes here:

 input type="text" id="vendor_name" name="vendor_name" onkeyup="showData(); 
+4
source share
1 answer

Why are you calling showData() on onkeyup trying to call a function on on onfocus instead of onkeyup . Other than that, I see no error in your code.

0
source

Source: https://habr.com/ru/post/1397996/


All Articles