View Full Version : check for null in shopping cart validation

09-21-2005, 10:14 PM
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)
if (datatype)
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;}

09-21-2005, 10:23 PM
If it can only be a number and is left blank, would you be able to use the isNaN() function to check?