9 Replies - 444 Views - Last Post: 23 March 2018 - 05:33 AM

#1 testmetestyou   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 19-July 16

how to disable Ajax if using input min

Posted 19 March 2018 - 05:09 AM

Hello

How can i disable ajax if using input min.

I have QTY 11 and qty minimum is 10 and one product price is 1$ If I lower qty to 10 then its 10$ and if I lower one more time then qty is still 10 and price is 9$ ajax still working and if I refresh then it will show 9 QTY and 9$.

So I want it disables if it reaches my input minimum. Every product have different minimum number.

AJAX
$(document).ready(function() {                           
  $("#btnplus<?php echo $i;?>").click(function() {   
    $.post("<?php echo $baseurl;?>/api-cart-update.php",{ 
      unique: "<?php echo $unique;?>",
      cccid: "<?php echo $data['id'];?>",
      act: "plus"
    },

      function(data) {
        $('#chk<?php echo $i;?>').html(data);
        $('#sum<?php echo $i;?>').html(data);
        $('#km<?php echo $i;?>').html(data);
      });
  });

  $("#btnminus<?php echo $i;?>").click(function() {
    $.post("<?php echo $baseurl;?>/api-cart-update.php",{ 
    unique: "<?php echo $unique;?>",
    cccid: "<?php echo $data['id'];?>",
    act: "minus"
  },

    function(data) {
      $('#chk<?php echo $i;?>').html(data);
      $('#sum<?php echo $i;?>').html(data);
      $('#km<?php echo $i;?>').html(data);
    });
  });
});


HTML(Input)
<td class="product-quantity">
  <button id="btnminus<?php echo $i;?>" onclick="var result = document.getElementById('qty<?php echo $i;?>'); var qty<?php echo $i;?> = result.value; if( !isNaN( qty<?php echo $i;?> ) &amp;&amp; qty<?php echo $i;?> &gt; <?php echo $ppp['minbuy']; ?> ) result.value--;return false;" class="reduced items-count" typy="button"><i class="zmdi zmdi-minus">&nbsp;</i></button>
    <input type="text" id="qty<?php echo $i;?>" class="input-text qty" title="Qty" value="<?php echo $data['qty']; ?>" min="<?php echo $ppp['minbuy']; ?>" maxlength="12" id="qty<?php echo $i;?>" name="qty" style="display:inline-block; width: 70px;">
  <button id="btnplus<?php echo $i;?>" onclick="var result = document.getElementById('qty<?php echo $i;?>'); var qty<?php echo $i;?> = result.value; if( !isNaN( qty<?php echo $i;?> )) result.value++;return false;" class="increase items-count" type="button"><i class="zmdi zmdi-plus">&nbsp;</i></button>
</td>


PHP min qty number
<?php echo $ppp['minbuy']; ?>


Best wishes

Is This A Good Question/Topic? 0
  • +

Replies To: how to disable Ajax if using input min

#2 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2958
  • View blog
  • Posts: 11,488
  • Joined: 03-December 12

Re: how to disable Ajax if using input min

Posted 19 March 2018 - 07:24 AM

You don't disable anything, you just don't call it. Do your check and if the minimum is not met, don't make the ajax call.
Was This Post Helpful? 0
  • +
  • -

#3 testmetestyou   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 19-July 16

Re: how to disable Ajax if using input min

Posted 19 March 2018 - 04:49 PM

I have problem, if my Input minimum is 12 and value is 14 it doesnt go to 12... it goes only 13...

$("#btnminus<?php echo $i;?>").click(function() {
 if($("#qty<?php echo $i; ?>").val() > $('#qty<?php echo $i; ?>').attr('min')){
    $.post("<?php echo $baseurl;?>/api-cart-update.php",{ 
      unique: "<?php echo $unique;?>",
      cccid: "<?php echo $data['id'];?>",
      act: "minus"
      },
    function(data) {
      $('#chk<?php echo $i;?>').html(data);
      $('#sum<?php echo $i;?>').html(data);
      $('#km<?php echo $i;?>').html(data);
    });
 } 
});

Was This Post Helpful? 0
  • +
  • -

#4 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2958
  • View blog
  • Posts: 11,488
  • Joined: 03-December 12

Re: how to disable Ajax if using input min

Posted 19 March 2018 - 05:18 PM

Your code is doing exactly what you set it to do, only work if the quantity is greater than the minimum.
Was This Post Helpful? 0
  • +
  • -

#5 testmetestyou   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 19-July 16

Re: how to disable Ajax if using input min

Posted 19 March 2018 - 05:48 PM

but how I can make work it value same as minimum and greater than minimum?
Was This Post Helpful? 0
  • +
  • -

#6 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2958
  • View blog
  • Posts: 11,488
  • Joined: 03-December 12

Re: how to disable Ajax if using input min

Posted 20 March 2018 - 06:09 AM

test some things out. is 5 >= 6?
Was This Post Helpful? 0
  • +
  • -

#7 testmetestyou   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 19-July 16

Re: how to disable Ajax if using input min

Posted 20 March 2018 - 06:57 AM

View Postastonecipher, on 20 March 2018 - 06:09 AM, said:

test some things out. is 5 >= 6?

it goes lower than 5....
Was This Post Helpful? 0
  • +
  • -

#8 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2958
  • View blog
  • Posts: 11,488
  • Joined: 03-December 12

Re: how to disable Ajax if using input min

Posted 20 March 2018 - 07:48 AM

JsFiddle
Was This Post Helpful? 0
  • +
  • -

#9 testmetestyou   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 19-July 16

Re: how to disable Ajax if using input min

Posted 22 March 2018 - 07:07 PM

Its not what I asked.. But I think this is PHP ajax problem than >= this jquery problem...
Was This Post Helpful? 0
  • +
  • -

#10 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2958
  • View blog
  • Posts: 11,488
  • Joined: 03-December 12

Re: how to disable Ajax if using input min

Posted 23 March 2018 - 05:33 AM

It is what you asked. You said you needed to prevent something from happening if the minimum was below a threshold.

It is not a PHP/ AJAX problem. PHP has nothing to do with the front end. They are completely separate.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1