Guest User

Untitled

a guest
Aug 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. Jquery Disabling individual buttons within search results that all have the same classes applied
  2. $("button.addtocart").click(function(e) {
  3. // fetch <input name='stock_amount'> within the clicked buttons form element
  4. var stock_amount_input = $("input[name='stock_amount']", $(this).parent());
  5. // fetch <input name='_qty'> within the clicked buttons form element
  6. var qty_input = $("input[name='_qty']", $(this).parent());
  7. // maybe you want to do some check here
  8. var new_amount = stock_amount_input.val() - qty_input.val();
  9. // set the new calculated value in the stock_amount input
  10. stock_amount_input.val(new_amount);
  11.  
  12. // if the new_amount is less than 1 we dissable the clicked button
  13. if(new_amount < 1) {
  14. $(this).attr("disabled", "disabled");
  15. }
  16. });
  17.  
  18. var nodes = $("form");
  19. for(var i=0; i<nodes.length; i++) {
  20. var node = nodes[i];
  21. // do something
  22. }
Add Comment
Please, Sign In to add comment