dspows0637 2014-05-16 03:07
浏览 52

如何在多个文本框中发布值

I had here a ajax function for posting data in pr field. What I need to do is post all the value base on pr# in my database. How I can post the other data in different textboxes using ajax? Below is my database structure and image and codes. Any help will be appreciate.

Pr Database Details Structure

Pr #  | Supplier  | Receipt #  | Receiver  |
--------------------------------------------
321-B | Villman   | 312312331  | John      |
556-B | Dockers   | 903232317  | William   |

Here's my Code

index.php

<select id="pr">
<?php ... ?>
</select>

<input id="pr_num">
<input id="supplier">
<input id="receipt">
<input id="receiver">

<script type="text/javascript">
$(document).ready(function()
{
$('input[id="pr"]').change(function()
{
var prjt_code = $("#pr").val();
$.ajax({
type: "POST",
url: "ajax.php",
data :"pr_code="+pr_code,
dataType:'html',
type:'POST',
   success:function(data){
  //alert(data);
    $('#pr_num').val(data);
   }
  });
return false;
});
});
</script>

Ajax.php

<?php
if(isset($_POST['pr_code'])) {
$pr_code= $_POST['pr_code'];

$sql = $mysqli->query("SELECT * FROM pr_table WHERE pr='$pr_code'");

while($row = $sql->fetch_assoc())
  {
  $code = $row['pr'];
  }
echo $code;
}
?>
  • 写回答

1条回答 默认 最新

  • douluokuang7184 2014-05-16 03:19
    关注

    You could add a class name for the pr_num textbox. let's say

    <input type="text" id="pr_num" class="pr_num_class"/>
    

    Then to iterate the textboxes use jQuery's .each() function

    $(".pr_num_class").each(function(){
        $(this).val("//your text here");
    })
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行