用于在多个文本框中回显选定数据的javascript php代码
我的表格有列表框ok 我正在使用一些javascript选择listbox更改事件的数据用于在多个文本框中回显选定数据的javascript php代码,javascript,php,Javascript,Php,我的表格有列表框ok 我正在使用一些javascript选择listbox更改事件的数据 <script> function showUser(str) { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {
<script>
function showUser(str) {
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("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","getdata.php?q="+str,true);
xmlhttp.send();
}
</script>
<select class="special-flexselect" name="society" onChange="showUser(this.value)">
<option value="" ></option>
<?php foreach ($society as $soc){ ?>
<option value="<?php echo $soc["society"]; ?>"><?php echo $soc["society"]; ?></option>
<?php }?>
</select>
**Data displays in below div**
<div id="txtHint"><b>Person info will be listed here...</b></div>
函数showUser(str){
if(window.XMLHttpRequest){
//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}否则{
//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText;
}
}
open(“GET”、“getdata.php?q=“+str,true”);
xmlhttp.send();
}
所以只有一个文本框(#txtHint
在本例中)起作用了吗?如果我把这个div Person信息放在这里,则不会。。。然后工作,但当我把文本框和相同的id放在文本框中,然后不工作…啊,你必须使用xy.value
而不是xy.innerHTML
当使用
和多个文本框时…如何调用每个文本框的id并在其中回显数据..我猜$row['city']
应显示在名为城市
的输入中?可以从数据库调用返回多行还是仅返回一行?
<input type="text" name="amount" />
<input type="text" name="coupon" />
<input type="text" name="city" />
<?php
$q = $_GET['q'];
$con = mysqli_connect('localhost','root','','circulation_scheme_prepaid');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM societymaster WHERE society = '".$q."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
echo $row['city'] ;
echo $row['amount'] ;
echo $row['coupon'] ;
}
mysqli_close($con);
?>