A form is dynamically created with PHP loop and presents one row from DB. I'm asking a user for input through prompt when he changes qty, but when I send it with AJAX to PHP it's empty. I guess it's because hidden input "new_message" is filled at the same time AJAX is sending values to PHP script so at that moment is blank. For the first row generated I get a message, but not for any other row.
Can you help me how to pass prompt input to PHP script?
//Update qty on article
$('.update_qty').on('change', function() {
var message = prompt("Upišite razlog za izmjenu količine:");
//e.preventDefault();
//Get message value
$('#new_message').val(message);
var data = $('#form1').serializeArray();
if (message != "" || message != NULL) {
$.ajax({
type: 'POST',
url: 'update_qty.php',
data: data,
success: function(data) {
alert(data);
}
});
} else {
alert("Empty");
e.PreventDefault();
return false;
}
});
<tbody>
<?php if (!empty($sales_plan_list)) {
foreach($sales_plan_list as $sales_key => $sales_value) {
?>
<tr class="new">
<td>
<a href="view_product_sales.php?id=<?php echo $sales_value['article_id']; ?>">
<?php echo $sales_value['article_no']; ?>
</a>
</td>
<td><?php echo $sales_value['description']; ?></td>
<td><?php echo myNumberFormat($sales_value['rrp']); ?></td>
<td>
<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; ?>">
<input type="hidden" name="new_message" id="new_message" value="">
</form>
</td>
<td>
<a href="view_product_sales.php?id=<?php echo $sales_value['article_id']; ?>" class="ti-eye" title="Pogledaj"></a>
<a href="edit_product_sales.php?id=<?php echo $sales_value['article_id']; ?>" class="ti-settings" title="Izmjeni"></a>
<a href="delete_product_sales.php?id=<?php echo $sales_value['article_id']; ?>$sales_plan_id=<?php echo $sales_plan_id; ?>" class="ti-trash" title="Obriši"></a>
</td>
</tr>
<?php
}
}
?>
</tbody>