Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- </head>
- <body>
- <div>
- <ul>
- <li>
- <span class="product-name">Product 1</span>
- <input type="text" class="qty-input" id="qty-1">
- </li>
- <li>
- <span class="product-name">Product 2</span>
- <input type="text" class="qty-input" id="qty-2">
- </li>
- <li>
- <span class="product-name">Product 3</span>
- <input type="text" class="qty-input" id="qty-3">
- </li>
- </ul>
- <button type="submit" id="submit">Buy</button>
- </div>
- <script type="text/javascript">
- $(document).ready(function(){
- // event on click
- $("#submit").click(function(){
- // loop
- $(".qty-input").each(function() {
- var productName = $(this).siblings('.product-name').text();
- if ($(this).val()) {
- alert('Product: ' + productName + '; Qty: ' + $(this).val());
- }
- });
- });
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement