| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Javascript Error Handling Help
I am not a programmer and am attempting to modify the script below - this is for a shopping cart and I do not want the number of items ordered to exceed the number in stock. It is a MSAccess database and the "<%= intStock %>" is the field that contains the quantity in stock.
If there is no change to 'value="1"' the order goes through with no error, on any change to "1" either greater or less than the inventory, I get an error message. If I input a number greater and get the error and then input a number within the inventory limits, I still get the error. If I put in a number greater than 1 but less than the inventory, I still get the error. The change is triggering the look for an error, but I'm not sure why it is not comparing the number entered to the inventory quantity and only returning the error for quantities greater than the inventory stock. Any help would be appreciated. ***** Customer input changes "value" to desired number to order ******* Add <input type="text" size="2" name="intQuant" value="1" onChange="HandleError(this)"> to my order. <input type="submit" value="Add to Cart" id="submit1" name="submit1"> ***** Javascript to verify "value" ***** <script LANGUAGE="JavaScript"> <!-- function AbortEntry(sMsg, eSrc) { window.alert(sMsg); // set focus and highlight to the offending error eSrc.focus(); //eSrc.select(); } function HandleError(eSrc) { // make sure the input is a numeric value var val = parseInt(eSrc.value); if (isNaN(val)) { return AbortEntry("Must be a number.", eSrc); } // make sure the value is not negative if (val <= 0) { return AbortEntry("Please enter a positive number.", eSrc); } // make sure the value is not greater than the number in stock if (val <= "<%= intStock %>") { return; } else { return AbortEntry("Please do not enter a quantity greater than our stock.", eSrc); } } //--> </script> |
|
#2
|
||||
|
||||
|
Quote:
My first question would be...Why??? If you aren't a programmer, then you should let a programmer at you company work on this. There are several things that would need to be checked. This would entail stepping through the code to determine the flow of it and find out why it isn't working. And since you aren't a programmer, I would once again have to ask "WHY" are you trying to do this??? |
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > Javascript Error Handling Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|