开发者

How to insert value to the text box using Ajax from the Drop Down Menu?The Result should be come on the Form Texbox How?

开发者 https://www.devze.com 2023-01-04 06:18 出处:网络
<script type=\"text/javascript\"> function showUser(str) { if (str == \"\") { document.getElementById(\"txtHint\").innerHTML = \"\";
<script type="text/javascript">
    function showUser(str) {
        if (str == "") {
            document.getElementById("txtHint").innerHTML = "";
            return;
        }
        // code for IE7+, Firefox, Chrome, Opera, Safari
        if (window.XMLHttpRequest) {
            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;
                //document.myForm.text1.value=.innerHTML=xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET", "getuser.php?q=" + str, true);
        xmlhttp.send();
    }
</script>

</head>

<body>
<form name="myForm">
    <p>Selec the Menu :
        <select name="users" onchange="showUser(this.value)">
            <option value="">Select ID</option>
<?php do { ?>
            <option value="<?php echo $row_rscustomer['customer_number']?>"><?php echo $row_rscustomer['customer_number']?></option>
<?php } while ($row_rscustomer = mysql_fetch_assoc($rscustomer));
    $rows = mysql_num_rows($rscustomer);
        if ($rows > 0) {
           开发者_如何转开发 mysql_data_seek($rscustomer, 0);
            $row_rscustomer = mysql_fetch_assoc($rscustomer);
        } ?>
        </select>
    </p>
    <p>&nbsp;</p>
    <p>
        <input name="text1" type="text"
               value="<?php include (" getuser.php");?>"/>
    <p>
</form>
<div id="txtHint"></div>


Hey - I noticed that, inside your AJAX onreadystatechange function, you have added xmlhttp.status==200 to your conditional. In some browsers, as AJAX is a client-side language, this isn't supported. If the member status isn't supported by the user's browser, then its default value will either be undefined or 0, either way the value will never be 200, thus the block inside that conditional won't be executed.

I suggest removing the xmlhttp.status==200 condition, and just relying on xmlhttp.readyState. I had this problem when I first started with AJAX.

0

精彩评论

暂无评论...
验证码 换一张
取 消