Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old July 12th, 2004, 12:18 PM
baldeagle baldeagle is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 baldeagle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.&nbsp;

<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>

Reply With Quote
  #2  
Old July 12th, 2004, 12:40 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,770 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 7 h 9 m 21 sec
Reputation Power: 469
Quote:
Originally Posted by baldeagle
I am not a programmer and am attempting to modify the script below

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???

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Javascript Error Handling Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT