AmberA Posted December 4, 2019 Share Posted December 4, 2019 <script> function myFunction() { var x, text; x = document.getElementById("qty").value; if (isNaN(x) || x < 2) { alert('ALERT HERE'); } else { } } </script> <input type="text" size="5" value="1" id="qty" class="form-control" name="{product.qtyboxname}" onblur="{product.recalculateprice}"/> <input type="submit" name="submit{product.productID}" onclick="myFunction();return confirm;" id="submit{product.productID}" value="{labels.cart.addToCartLink}" class="btn btn-default"/> The script works perfectly as I need an alert when a quantity of less than 2 is entered, however, it only shows an 'OK' button on the alert box which takes you directly to the cart page. How can I get the 'return confirm' to work so they have an option to carry onto the cart or to cancel and stay on the same page? Link to comment Share on other sites More sharing options...
Ingolme Posted December 4, 2019 Share Posted December 4, 2019 Confirm is a function, so call it with parentheses: return confirm("Do you want to continue?"); I would recommend putting this code in an submit event of the form rather than the click event of a button, so that even if the user submits the form through other means (pressing Enter in the text field) the code will still run. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now