Advertisement
Guest User

Untitled

a guest
May 24th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 KB | None | 0 0
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  4. <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
  5. <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
  6. <%@ page isELIgnored="false"%>
  7.  
  8. <fmt:setLocale value="bg_BUL" />
  9. <fmt:setBundle basename="i18n.text" />
  10.  
  11. <!DOCTYPE html>
  12. <html>
  13.  
  14. <head>
  15. <script src="https://code.jquery.com/jquery-3.4.1.min.js"
  16. integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
  17.  
  18. <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
  19.  
  20. <meta charset="UTF-8">
  21. <title>
  22. <fmt:message key="TITLE" />
  23. </title>
  24. </head>
  25. <header>
  26. <h1>
  27. <fmt:message key="TITLE" />
  28. </h1>
  29. </header>
  30.  
  31. <body>
  32.  
  33. <script>
  34. $(document).ready(function () {
  35. $(".operator").click(function (event) {
  36. var text = event.target.id;
  37. var pattern = /\d/g;
  38. var id = text.match(pattern);
  39. var subtotalOfProduct = $("#product_base_price" + id).val() * $("#number" + id).val();
  40.  
  41. $("#product_total_price" + id)
  42. .text(subtotalOfProduct);
  43.  
  44. var rows = $("tr");
  45. var total = 0;
  46. var i = 0;
  47. var length = $(".total").length;
  48. console.log(length);
  49. while (i <= length) {
  50. let currentRow = rows[i];
  51.  
  52. console.log(currentRow);
  53. total = total + $("#product_total_price" + i).val();
  54. i++;
  55. }
  56. $("#orderCost").text(total);
  57. });
  58. });
  59.  
  60. </script>
  61.  
  62.  
  63.  
  64. <div>
  65. <table>
  66. <thead>
  67. <tr>
  68. <th colspan="2">
  69. <fmt:message key="PRODUCT" />
  70. </th>
  71. <th>
  72. <fmt:message key="PRICE" />
  73. </th>
  74. <th>
  75. <fmt:message key="QUANTITY" />
  76. </th>
  77. <th>
  78. <fmt:message key="SUBTOTAL" />
  79. </th>
  80. <th></th>
  81. </tr>
  82. </thead>
  83. <tbody>
  84. <c:forEach items="${requestScope.cartProducts}" var="cp">
  85. <tr>
  86. <td>
  87. <div>
  88. <img src="http://placehold.it/100x100" class="img-responsive" />
  89. </div>
  90. </td>
  91. <td>
  92. <div>
  93. <h4>${cp.name}</h4>
  94. </div>
  95. </td>
  96. <td>${cp.price}</tdid>
  97.  
  98. <td>
  99. <form name="quantityForm" method="post">
  100. <input style="font-size: 21px;" type="button" value="-" id="btn${cp.id}"
  101. onclick='javascript: document.getElementById("number${cp.id}").value--;'
  102. class="operator">
  103.  
  104. <input id="number${cp.id}" type="number" name="quantity" min="1" max="100"
  105. value="${cp.quantity}">
  106.  
  107. <input id="btn${cp.id}" style="font-size: 21px;" type="button" value="+"
  108. onclick='javascript: document.getElementById("number${cp.id}").value++;'
  109. class="operator">
  110.  
  111. </form> <input type="hidden" id="product_base_price${cp.id}" value="${cp.price}">
  112. <td>
  113. <div id="product_total_price${cp.id}" class="total">${cp.price * cp.quantity }</div>
  114. </td>
  115. <%-- <input type="hidden" id="orderCostHidden" value="${orderCost + cp.price * cp.quantity}"> --%>
  116. <c:set var="orderCostInitial" scope="session"
  117. value="${orderCostInitial + cp.price * cp.quantity}" />
  118. <td>
  119. <button class="btn btn-danger btn-sm">
  120. <i class="fa fa-trash-o"></i>
  121. </button>
  122. </td>
  123. </tr>
  124.  
  125. </c:forEach>
  126. <c:set var="length" value="${fn:length(cp)}" />
  127. </tbody>
  128. <tfoot>
  129. <tr>
  130. <td align="center" class="text-center"><strong>
  131. <fmt:message key="TOTAL" />
  132. <div id="orderCost">${orderCostInitial}</div>
  133. </strong></td>
  134. </tr>
  135. <tr>
  136. <td><a href="#" class="btn btn-warning"><i class="fa fa-angle-left"></i>
  137. <fmt:message key="CONTINUE_SHOPPING" /></a></td>
  138. <td colspan="2" class="hidden-xs"></td>
  139. <td><a href="/cmania/checkout" class="btn btn-success btn-block">
  140. <fmt:message key="CHECKOUT" /><i class="fa fa-angle-right"></i>
  141. </a></td>
  142. </tr>
  143.  
  144. </tfoot>
  145.  
  146. </table>
  147. </div>
  148.  
  149.  
  150.  
  151. </body>
  152. <footer>
  153. <fmt:message key="COPYRIGHT" />
  154. </footer>
  155.  
  156. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement