Advertisement
Daniel3996

buy_items.php

Dec 11th, 2023
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.  
  7. <meta http-equiv="refresh" content="15">
  8. <link rel="stylesheet" href="styles/buy_item_style.css">
  9. <link href='https://fonts.googleapis.com/css?family=Alkatra' rel='stylesheet'>
  10.  
  11. <title>Checkout</title>
  12.  
  13. <style>
  14. /* Add some basic styling for the buttons */
  15. .quantity-btn {
  16. cursor: pointer;
  17. font-size: 16px;
  18. padding: 5px 10px;
  19. margin: 0 5px;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <?php
  25.  
  26. $item = htmlspecialchars($_GET['item']);
  27. $price = htmlspecialchars($_GET['price']);
  28.  
  29.  
  30. ?>
  31. <Header>
  32. <h1>Items</h1>
  33. </Header>
  34. <form action="checkout.php" method="get">
  35. <h2><?php echo $item ?></h2>
  36. <p>Price: <strong id="item-price"><?php echo $price ?></strong></p>
  37.  
  38. <!-- Plus and minus buttons for quantity -->
  39. <button type="button" class="quantity-btn" onclick="updateQuantity('minus')">-</button>
  40. <input type="text" id="quantity" name="quantity" value="1" readonly>
  41. <button type="button" class="quantity-btn" onclick="updateQuantity('plus')">+</button>
  42.  
  43. <!-- Display total price -->
  44. <p>Total Price: Rs:<strong id="total-price"><?php echo $price ?></strong></p>
  45.  
  46. <button>
  47. <a id="checkout">Checkout</a>
  48. </button>
  49. <button><a href="index.html">Cancel and Return back</a></button>
  50. </form>
  51.  
  52. <script>
  53. // Function to update quantity and total price
  54. function updateQuantity(action) {
  55. var quantityInput = document.getElementById('quantity');
  56. var quantity = parseInt(quantityInput.value);
  57.  
  58. if (action === 'plus') {
  59. quantity += 1;
  60. } else if (action === 'minus' && quantity > 1) {
  61. quantity -= 1;
  62. }
  63.  
  64. quantityInput.value = quantity;
  65.  
  66. var itemPrice = parseFloat(<?php echo $price ?>);
  67. var totalPrice = quantity * itemPrice;
  68.  
  69. document.getElementById('total-price').textContent = totalPrice.toFixed(2);
  70.  
  71. var checkoutLink = document.getElementById("checkout")
  72. checkoutLink.href = 'checkout.php?item=<?php echo $item ?>&price=<?php echo $price ?>&quantity=' + quantity;
  73. }
  74. </script>
  75. </body>
  76. </html>
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement