Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2003
    Posts
    111
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question check for null in shopping cart validation

    This javascript checks to make sure a customer selected a number between the minimum and maximum quantity as they add an item to their shopping cart - it works fine except if they don't enter a quantity at all and just hit the "add to cart" button they get a "cannot INSERT null value" error. So how do I add in a way to check that they did not leave the field blank. (I have tried various null checks and have been unsuccessful)

    <SCRIPT TYPE="text/javascript">
    function valuevalidation(entered, min, max, alertbox, datatype)
    {
    with (entered)
    {
    checkvalue=parseFloat(value);
    if (datatype)
    {smalldatatype=datatype.toLowerCase();
    if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};
    }
    if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue )
    {if (alertbox!="") {alert(alertbox);} return false;}
    else {return true;}
    }
    }
    </script>

  • #2
    New to the CF scene
    Join Date
    Sep 2005
    Location
    Michigan
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If it can only be a number and is left blank, would you be able to use the isNaN() function to check?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •