如何将查询结果用作ajax中的变量

时间:2017-10-15 08:39:16

标签: javascript php html ajax

我有一个表单,其中有一个表单输入字段用于优惠券折扣。如果我点击按钮,则优惠券结果显示在div部分。但我想将此结果作为变量,我可以在其他输入字段总价上使用它。我想用优惠券结果替换 $ total_package_price

HTML

scanf(" %b",&b); 
      ^^^
      space in the scanf

的JavaScript

<li>
            <span class="txt_hd">Total Price</span>
            <span class="txt_inp"><input type="text" name="ttlprice" id="main_price" readonly value="<?php echo $total_package_price; ?>" /></span>
        </li>
 <li style="display:none;" id="apply_omron_dis">
            <span class="txt_hd">To Avail Discount, Put the Coupon Code here</span>
            <span class="txt_inp"><input type="text" name="omron_coupon_code" id="omron_coupon_code" /></span>
           <span class="txt_hd" style="visibility:hidden">To Avail OMRAN Discount, Put the Coupon Code here</span><input type="button" name="apply_coupon" id="apply_coupon" onClick="getcoupon();" value="Apply"/>
            <input type="button" id="cancel" value="cancel"/><span id="txtHint"></span>
        </li>

PHP

<script>
   function getcoupon()
  {
  var omron_coupon_code = document.getElementById("omron_coupon_code").value;

   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 (this.readyState == 4 && this.status == 200) {
            document.getElementById("txtHint").innerHTML = this.responseText;
        }
    };
    xmlhttp.open("GET","function.php?omron_coupon_code="+omron_coupon_code,true);
    xmlhttp.send();
}

0 个答案:

没有答案