获取隐藏字段的值

Get value of hidden fields

当 update_qty 随更改事件发生更改时,我正在尝试获取表单中隐藏字段的值。表单由 php 循环生成,并显示来自数据库的一行。我需要使用 onchange 事件获取 update_qty 并获取更新行的所有隐藏字段。

下面是我正在使用的代码,你能给我指明正确的方向吗?我无法让它工作。我总是从第一行的隐藏字段中获取值。

//This form is dynamiclly genrated buy php loop. All input fields are one row from DB. 

<form name="form1" id="form1" method="POST" action="update_qty.php">
<input type="text" name="update_qty" class="update_qty" id="qty" value="<?php echo $sales_value['qty'] ?>"><?php echo ' Kom'; ?>
<input type="hidden" name="article_id" id="article_id" value="<?php echo $sales_value['article_id']; ?>">
<input type="hidden" name="sales_plan_id" id="sales_plan_id" value="<?php echo $sales_plan_id; ?>">
<input type="hidden" name="product_mix_id" id="product_mix_id" value="<?php echo $product_mix_id; ?>">
</form>

    //Update qty on article
$(document).ready(function() {

    $('.update_qty').on('change', function() {

        var message = prompt("Upišite razlog za izmjenu količine:");
        alert(message);
        //e.preventDefault();
        var article_id = $("#article_id").val();
        var sales_plan_id = $("#sales_plan_id").val();
        var update_qty = $(this).val();
        var product_mix_id = $("#product_mix_id").val();


        if (message != "" || message != NULL) {
            $.ajax({
                type:'POST',
                url:'update_qty.php',
                data:{ article_id: article_id, sales_plan_id: sales_plan_id, update_qty: update_qty, product_mix_id: product_mix_id, message: message },
                success:function(data) {
                    alert(data);
                }
            });
        } else {
            e.PreventDefault();
            return false;
        }

    });

});

您可以序列化整个表单而不是获取所有输入:

$(function() {
  $('.update_qty').on('change', function(e) {
    var data = $('#form1').serializeArray();
    console.log(data);
  });
});