Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation...Make sure enough in stock

Status
Not open for further replies.

jojo79

Programmer
Oct 11, 2006
40
US
SQL 2000
ASP

I am trying to figure out a way to validate a textbox on a form to make sure before they submit the form or use the onChange function, I need to make sure that the number they enter, I have enough of that product in my database.

Example
I have 5 Apples in my tbl_stock table. Some requests 8 Apples, I need an error msg to pop up and tell that person, I only have 5. I have tried to think of many ways to do this. I think I can do this with a SQL Statement, but I am just not sure how to put it all together. Much thanks
 
That will require one of two things:

1. You can load all the total inventory at the top of your page before anything is checked against, then on a submit or onchange compare.

2. Create an AJAX function to be called on onsubmit or onchange and dynamically check the value.

By far, I recommend the second method.
 
Use a select box so they can only select from 1 to num_in_stock.

Display on the page how many are in stock.

put the num_in_stock into a javascript onBlur event for the text box.

Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 
Use a select box so they can only select from 1 to num_in_stock.

Display on the page how many are in stock.

That's a pretty good idea. Both together.
 

You should still validate the value at the server before submitting the order - don't rely on users or their chosen browsers to follow your rules clientside.

A smile is worth a thousand kind words. So smile, it's easy! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top