簡體   English   中英

如何使用ajax根據其先前的文本框值填充文本框

[英]How to fill a textbox based on its previous textbox value using ajax

我有一個這樣的

 <div class="row1"> <input type="text" class="pinCode" name="pin[]" value=""> <input type="text" class="areaName" name="location[]" value=""> </div> <div class="row1"> <input type="text" class="pinCode" name="pin[]" value=""> <input type="text" class="areaName" name="location[]" value=""> </div> <div class="row1"> <input type="text" class="pinCode" name="pin[]" value=""> <input type="text" class="areaName" name="location[]" value=""> </div>

我在數據庫中有一個名為“city”的表,其中有兩列“pincode”和“cityname”。 當我填充 pinCode 文本框時,我想用城市的名稱填充 CityName 文本框以輸入 pincode。 請建議一些 Jquery 或 ajax 代碼和 php 成功頁面,因為我是初學者。

在鼠標超出密碼時,您可以調用這樣的 ajax 函數,

 $(document).on("mouseOut or onBlur",".pincode",function() {
    var pincode = $(this).val();
    $.ajax({
         url: "ajax.php",
         type: "POST",
         dataType: "HTML",
         async: false,
         data: {"pincode": pincode},
         success: function(data) {
               // data will have the area name echo'ed in ajax.php file
               $(this).closest('areaName').val(data);

      }
  });
});

ajax.php

your code to get the area name based on pincode

echo $areaname;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM