Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.94 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  5. </head>
  6. <body>
  7.  
  8. <div>
  9.     <ul>
  10.         <li>
  11.             <span class="product-name">Product 1</span>
  12.             <input type="text" class="qty-input" id="qty-1">
  13.         </li>
  14.         <li>
  15.             <span class="product-name">Product 2</span>
  16.             <input type="text" class="qty-input" id="qty-2">
  17.         </li>
  18.         <li>
  19.             <span class="product-name">Product 3</span>
  20.             <input type="text" class="qty-input" id="qty-3">
  21.         </li>
  22.     </ul>
  23.     <button type="submit" id="submit">Buy</button>
  24. </div>
  25.  
  26. <script type="text/javascript">
  27. $(document).ready(function(){
  28.   // event on click
  29.   $("#submit").click(function(){
  30.     // loop
  31.     $(".qty-input").each(function() {
  32.         var productName = $(this).siblings('.product-name').text();
  33.  
  34.         if ($(this).val()) {
  35.             alert('Product: ' + productName + '; Qty: ' + $(this).val());
  36.         }
  37.     });
  38.   });
  39. });
  40. </script>
  41.  
  42. </body>
  43. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement