Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. (function($){
  2. function spin() {
  3. $(".foods").spinner({min: 0, max: 100, step: 1});
  4. $('.foods').addClass("enabled");
  5. }
  6.  
  7. function updatePrice(){
  8. var Subtotal = 0;
  9. var tax = 0;
  10. var total = 0;
  11. $(".foods").each(function(){
  12. var price_text = $(this).closest("tr").find("td:nth-child(2)").text();
  13. var price = parseFloat(price_text.replace(/[^0-9\.]+/g,""));
  14. Subtotal = Subtotal + price * $(this).val();});
  15. Subtotal = Subtotal.toFixed(2);
  16. $("#Subtotal").val(Subtotal);
  17. tax = Subtotal * 0.13;
  18. tax = tax.toFixed(2);
  19. $("#Tax").val(tax);
  20. total = parseFloat(Subtotal) + parseFloat(tax);
  21. total = total.toFixed(2);
  22. $("#Total").val(total);
  23. }
  24.  
  25. function disablePrice(){
  26. if ($("#Koobideh_Kabob").val() < 1 && ("#Koobideh_Kabob_extra").hasClass("enabled")) {
  27. $("#Koobideh_Kabob_extra").prop("readonly", true);
  28. $("#Koobideh_Kabob_extra").val(0).trigger("spinchange");
  29. $("#Koobideh_Kabob_extra").spinner("destroy");
  30. $("#Koobideh_Kabob_extra").removeClass("enabled");
  31. } else {
  32. $("#Koobideh_Kabob_extra").prop("readonly", false);
  33. $("#Koobideh_Kabob_extra").spinner({min: 0, max: 100, step: 1});
  34. $("#Koobideh_Kabob_extra").addClass("enabled");
  35. };
  36. if ($("#Joojeh_Kabob").val() < 1 && $("#Joojeh_Kabob_extra").hasClass("enabled")) {
  37. $("#Joojeh_Kabob_extra").prop("readonly", true);
  38. $("#Joojeh_Kabob_extra").val(0).trigger("spinchange");
  39. $("#Joojeh_Kabob_extra").spinner("destroy");
  40. $("#Joojeh_Kabob_extra").removeClass("enabled");
  41. } else {
  42. $("#Joojeh_Kabob_extra").prop("readonly", false);
  43. $("#Joojeh_Kabob_extra").spinner({min: 0, max: 100, step: 1});
  44. $("#Joojeh_Kabob_extra").addClass("enabled");
  45. };
  46. }
  47.  
  48. $(document).ready(function() {
  49. spin();
  50. disablePrice();
  51. $(".foods").on("spinchange", updatePrice);
  52. $("#Koobideh_Kabob").on("spinchange", disablePrice);
  53. $("#Koobideh_Kabob").on("spinchange", updatePrice);
  54. $("#Joojeh_Kabob").on("spinchange", disablePrice);
  55. $("#Joojeh_Kabob").on("spinchange", updatePrice);
  56. });
  57. }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement