0

I'm trying to get a user entering the reason for updating qty before ajax submits the qty to db.

This is jquery code which sends qty change to the php script which updates db. For some reason, I can't stop ajax and display a prompt for a user to display so he could write a reason why he is updating qty. Can someone tell me why prompt is not being displayed?

<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;
        }

    });

});
Budimir
  • 39
  • 1
  • 12

1 Answers1

0

try like this using beforesend.

Update:

    $(document).ready(function() {
var message;

      $('#update_qty').on('blur', function() {

    //e.preventDefault();
    var article_id = $("#article_id").val();
    var sales_plan_id = $("#sales_plan_id").val();
    var update_qty = $("#update_qty").val();
    var product_mix_id = $("#product_mix_id").val();



      $.ajax({
        type:'POST',
        beforesend:con(),
        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 },
        success:function(data) {
          alert(data);
        }
      });


  });

});

function con(xhr){
    message=prompt('enter reason');
    if(message==''){
     xhr.abort();

     }
    }
jasinth premkumar
  • 1,430
  • 1
  • 12
  • 22