JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 12th, 2004, 12:27 PM
baldeagle baldeagle is offline
Registered User
Dev Articles 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
Question Error routine 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, 01:05 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Error routine 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 5 hosted by Hostway
Stay green...Green IT