所以,我有一个由2个文本输入栏和一个DIV组成的页面。如何在页面加载时触发Javascript函数?
第一个输入文本字段是用户输入数据的位置,第二个输入文本字段是只读的。在第一个输入文本字段中按Enter键后,将根据在数据库中查询的内容在DIV中加载单独的页面。
问题是我需要传递一个值到第二个输入字段,它是只读来自同一个数据查询。请帮我...
示例代码:我做了一个单独的应用程序,因为这基本上是应该发生在我的应用程序。
的index.php:
<!DOCTYPE html>
<html>
<head>
<script>
function loadNow(p,d){
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(d).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET",p,true);
xmlhttp.send();
}
</script>
</head>
<body>
<input type="text" id="input1" name="input1" placeholder="Input Here"
onkeyup="if ((event.which == 13) || (event.keyCode == 13)) {
loadNow('testnewpage1.php?r='+this.value,'loadHere1'); }" />
<input type="text" id="input2" name="input2" readonly />
<div id="loadHere1">
</div>
</body>
</html>
testnewpage1.php
<?php
require('conn.php');
$r=$_GET['r'];
$query = mssql_query("select somefield from sometable where reference='$r'");
$data = mssql_fetch_array($query);
echo "
<script>
input2.value='$data[somefield]';
</script>
";
?>
编辑:即使警报();功能不起作用。
数据是否被加载到只读文本框中您希望查询产生的相同数据?或者查询输出是否有比所需更多的数据? – 2014-10-08 08:47:47
是的,它实际上是相同的查询,但查询将输出1行或更多行,所以我只需要从行中显示相同的值。那么,我想如何让它按照我的喜好工作,无论如何,谢谢! – user3462418 2014-10-08 09:06:06