[英]how to display the values in a text-box by retrieving that values from the database?
I'm doing a database project. 我正在做一个数据库项目。 I have a webpage where i have 5 textboxes.
我有一个网页,我有5个文本框。 In one of the textboxes, when it is on focus, I should show to the user the values present in the database.
在其中一个文本框中,当它处于焦点时,我应该向用户显示数据库中存在的值。 I know how to retrieve using javascript and AJAX but am not able to display the retrieved values in the textbox.I tried a lot but couldn't get it.
我知道如何使用javascript和AJAX检索,但我无法在文本框中显示检索到的值。我尝试了很多,但无法得到它。
Can anyone help me in doing 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];
}
display I m using the showData string as above. 显示我使用上面的showData字符串。 To autocomplete I have to make some changes here:
要自动完成,我必须在此处进行一些更改:
input type="text" id="vendor_name" name="vendor_name" onkeyup="showData();
Why are you calling showData()
on onkeyup
try to call function on onfocus
instead of onkeyup
. 你为什么在
onkeyup
上调用showData()
尝试在onfocus
上调用函数而不是onkeyup
。 Other than that I cant see any error on your given code. 除此之外,我无法看到您的代码有任何错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.