|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
Have you viewed the rendered source code to verify that <%= intStock %> is being displayed correctly? If it is, perhaps consider removing the quotes from around the value. I don't know that they'd cause a problem, but it's something to try.
__________________
Please don't PM me asking for solutions outside the scope of a thread. Keeping all responses in a thread stands to help others who come along later, which is after all what this forum's all about. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Error routine help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|