简体   繁体   English

如何使用jQuery在每个组中具有相同类名的多个输入文本框中插入值?

[英]How to insert a value in a multiple input textbox with the same class name per group using jQuery?

How to insert a value per group in a multiple input textbox with the same class name. 如何在具有相同类名的多个输入文本框中为每个组插入值。 I want to update the input textbox value per group. 我想更新每个组的输入文本框值。 My code below is working but it is filling up all textboxes when I select an item in autocomplete. 我下面的代码可以正常工作,但是当我选择自动完成中的项目时,它会填满所有文本框。 What I want is if I select an item in itemgroup 1, only textboxes in group 1 should update. 我想要的是,如果我在项目组1中选择了一个项目,则仅应更新组1中的文本框。

<div id="itemgroup1">
  <input type="text" class="form-control itemname" name="oe_type[]" placeholder="Enter item name or code" required>
  <input type="text"class="form-control it_desc" name="oe_desc[]" placeholder="Enter item description" required>                                     
  <input type="number" step="any" class="form-control it_price" name="oe_value[]" placeholder="Enter unit price" value="0">
  <input type="number" step="any" min="1" class="form-control itemqty" name="oe_qty[]" placeholder="Enter quantity" required>
</div>
<div id="itemgroup2" >
  <input type="text" class="form-control itemname" name="oe_type[]" placeholder="Enter item name or code" required>
  <input type="text"class="form-control it_desc" name="oe_desc[]" placeholder="Enter item description" required>
  <input type="number" step="any" class="form-control it_price" name="oe_value[]" placeholder="Enter unit price" value="0">
  <input type="number" step="any" min="1" class="form-control itemqty" name="oe_qty[]" placeholder="Enter quantity" required>
</div>
<script>
  $(".itemname").autocomplete({
    minLength: 4,
    autoFocus: true,
    source: function(request, response) {
      $.ajax({
        url: "get_item.php",
        data: {term: request.term},
        dataType: "json",
        success: function(data) {
          response($.map(data.myData, function(item) {
            return {
              label: item.name,
              value: item.code,
              code: item.code,
              price: item.price,
              desc: item.desc
            }
          }));
        }
      });
    },
    select: function (event, ui) {
      $(".it_desc").val(ui.item.desc);
      $(".it_price").val(ui.item.price);
      $(".itemqty").focus();
    }
  });
</script>

try this one: 试试这个:

select: function(event, ui) {
  $(this).nextAll(".it_desc").val(ui.item.desc);
  $(this).nextAll(".it_price").val(ui.item.price);
  $(this).nextAll(".itemqty").focus();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用jquery获取多个相同类名的跨度值 - How to get span value for multiple of the same class name using jquery 如何在jQuery中将值插入具有相同类名的文本框 - How to insert value to textboxes having same class name in jquery 如何在Codeigniter中使用具有相同名称的多个输入插入数据 - How To Insert Data Using Multiple Input With Same Name in codeigniter 如何使用jquery从具有相同类名的输入中获取最大值 - how to get the max value from an input of having same class name using jquery 每毫秒以毫秒级(setInterval)收集具有相同Class的所有输入的值,并将其包装-使用Jquery - Collect value of all input with same Class dinamically per milliseconds(setInterval), and wrap it - Using Jquery 使用jQuery比较具有相同类名但不具有相同ID的多个输入字段 - comparison of multiple input fields with same class name but not same id using jQuery 使用jQuery的具有相同名称但不同ID的多个输入字段的总和 - Sum of multiple input fields with same name but not same id using jQuery 多个具有相同ID和类名称的文本框的addeventlistener - addeventlistener for multiple textbox with same id and class name 具有相同类别名称的多个输入的输入类型范围的显示值 - Display value of input type range for multiple inputs with same class name 从 jQuery 中的多个相同类名获取值 CSS - Get value CSS from multiple same class name in jQuery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM