javascript php代码在多个文本框中回显所选数据

时间:2015-02-20 14:11:10

标签: javascript php

我的表单有列表框确定

我正在使用一些javascript选择列表框更改事件的数据

<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>

但我需要在多个文本框中回显数据..那么在javascript中要改变什么以及如何在这里回显所有文本框中的数据..

请帮助我...

下面是我需要回显数据的3个文本框

<input type="text"   name="amount" />
<input type="text"   name="coupon" />
<input type="text"   name="city" />

php code

<?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);
?>

0 个答案:

没有答案