close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Restricting quantity based on number of items in stock?

Thread began 2/24/2011 2:30 am by Nathon Jones Web Design | Last modified 3/15/2011 10:54 am by Jason Byrnes | 2027 views | 9 replies |

Nathon Jones Web Design

Restricting quantity based on number of items in stock?

We have a field in our product database that details the number in stock of a particular product.

Is it possible to restrict the quantity selected by a user, based on this stock number? For example, if a user attempts to purchase 5 of an item, which only has 1 showing as in stock, an error would be produced informing them of the quantity available.

Sorry, I should add that I don't need the purchasing process to update the stock level, I just need to restrict the quantity, availabile to purchase, based on the stock level.

We're using Classic ASP btw.

Thanks.
Nath.

Sign in to reply to this post

Jason ByrnesWebAssist

you could use server validation for this, though it will only work on a detail page with only one add to cart button.

add a hidden form element to the add to cart button form, in the property inspector click the plus button next to initial value and set it to use the available quantity column

add server validation from validation toolkit, select numeric validation.

For the server variable, select the quantity box. in the numeric validation setting set the maximum number to:
<%= Request.Form("qtyAvail") %>


where qtyAvail is the name of the hidden form element.

you can then add a validation show if behavior to show the message when validation fails.

Sign in to reply to this post

Nathon Jones Web Design

Syntax error?

Thank you Jason.

I've getting a syntax error with that...

Microsoft VBScript compilation (0x800A03EA)
Syntax error
/springparknursery/plant-information.asp, line 16, column 79
WAFV_Errors = WAFV_Errors & WAValidateNM(cStr(Request.Form("qtyAvail")) & "",0,<%= Request.Form("qtyAvail")

I assume this is because I am using a form variable as the maximum number value?

How do I set the maximum number to be the hidden form element? I notice the default is set to 100, but when I insert <%= Request.Form("qtyAvail") %> it generates the syntax error.

Hope you can help with that. Thanks.
Nath.

EDIT:

I've tried changing the line of code to the following:
WAFV_Errors = WAFV_Errors & WAValidateNM(cStr(Request.Form("spCART_1_Quantity_Add")) & "",0,Request.Form("qtyAvail"),"",",.",true,1)

...but, whilst this no longer produces a syntax error, the validation doesn't work.

Here's the code for my Add to Cart button:

<form name="spCART_1_ATC_<%=rsH.Fields("heatherID").value%>" method="post" action="<%=cStr(Request.ServerVariables("SCRIPT_NAME"))%><%=WA_eCart_IIf((Request.ServerVariables("QUERY_STRING") <> ""), "?" & Request.ServerVariables("QUERY_STRING"), "")%>">
<input type="hidden" name="spCART_1_ID_Add" value="<%=rsH.Fields("heatherID").value%>" />
<p>Quantity: <br />
<input type="text" name="spCART_1_Quantity_Add" value="1" size="6" style="width: 40px;height: 20px;border: 2px solid #BACBBE;padding: 6px 0px 6px 8px;margin: 0;color: #18440D;font:14px Arial, Helvetica, sans-serif;font-weight: normal;vertical-align:middle;" />
<input type="image" src="heather-plants/btn-addtobasket.png" value="Add to Cart" name="spCART_1_ATC" alt="Add to Basket" style="vertical-align:middle;" />
<input name="qtyAvail" type="hidden" id="qtyAvail" value="<%=(rsH.Fields.Item("heatherinstock").Value)%>" />
</p>
</form>

...and here is the server validation code:

<%
if (cStr(Request.Form("spCART_1_ATC.x")) <> "") then
WAFV_Redirect = "plant-information.asp"
Session("WAVT_plantinformation_Errors") = ""
if (WAFV_Redirect = "") then
WAFV_Redirect = cStr(Request.ServerVariables("SCRIPT_NAME"))
end if
WAFV_Errors = ""
WAFV_Errors = WAFV_Errors & WAValidateNM(cStr(Request.Form("spCART_1_Quantity_Add")) & "",0,Request.Form("qtyAvail"),"",",.",true,1)

if (WAFV_Errors<> "") then
PostResult WAFV_Redirect,WAFV_Errors,"plantinformation"
end if
end if
%>

Sign in to reply to this post

Jason ByrnesWebAssist

can you send a copy of your page so i can see the code in context.

Sign in to reply to this post

Nathon Jones Web Design

page

Hi Jason,

Copy of the page, attached. Thank you.

Regards
Nath.

Attached Files
RestrictQuantityPage.zip
Sign in to reply to this post

Jason ByrnesWebAssist

the code looks correct, can you post a link where i can see the issue.

Sign in to reply to this post

Nathon Jones Web Design

link

I've uploaded that to a temporaty page at:
plant-informationTEST.asp?hid=133

I've added details of the "quantity available" just below the price so you know how many to enter in the quantity box in order to trigger the validation error.

Appreciate the help, as ever.
Regards
Nath.

Sign in to reply to this post

Nathon Jones Web Design

form?

Do you think it's a problem with the form?

<form name="spCART_1_ATC_<%=rsH.Fields("heatherID").value%>" method="post" action="<%=cStr(Request.ServerVariables("SCRIPT_NAME"))%><%=WA_eCart_IIf((Request.ServerVariables("QUERY_STRING") <> ""), "?" & Request.ServerVariables("QUERY_STRING"), "")%>">
<input type="hidden" name="spCART_1_ID_Add" value="<%=rsH.Fields("heatherID").value%>" />
<p>Quantity: <br />
<input type="text" name="spCART_1_Quantity_Add" value="1" size="6" style="width: 40px;height: 20px;border: 2px solid #BACBBE;padding: 6px 0px 6px 8px;margin: 0;color: #18440D;font:14px Arial, Helvetica, sans-serif;font-weight: normal;vertical-align:middle;" />
<input type="image" src="heather-plants/btn-addtobasket.png" value="Add to Cart" name="spCART_1_ATC" alt="Add to Basket" style="vertical-align:middle;" />
<input name="qtyAvail" type="hidden" id="qtyAvail" value="<%=(rsH.Fields.Item("heatherinstock").Value)%>" />
</p>
</form>

I've tried deleting and rebuilding the page but the validation just doesn't work. As you say, everything seems to be in place.

Hope you can help with that. Thank you.
Regards
Nath.

Sign in to reply to this post

Nathon Jones Web Design

Problem with the form variable

Hi Jason,

I think it's a problem with using a form variable in the validation script. I tried just adding a number, instead of the form variable, and it appears to work.

Do you know how I would change the code to allow entry of the form variable? I assume it's the quotes in the 'Request.Form("qtyAvail")' that's causing the issue?

For example, this works:
WAFV_Errors = WAFV_Errors & WAValidateNM(cStr(Request.Form("PPcart_1_Quantity_Add")) & "",0,5,"",",.",true,1)

But this doesn't:
WAFV_Errors = WAFV_Errors & WAValidateNM(cStr(Request.Form("PPcart_1_Quantity_Add")) & "",0,Request.Form("qtyAvail"),"",",.",true,1)

How do I comment out the quotes? Appreciate the help, thank you.
Nath.

Sign in to reply to this post

Jason ByrnesWebAssist

I have created a support ticket so we can look into this issue further.

To view and edit your support ticket, please log into your support history:
supporthistory.php

If anyone else is experiencing this same issue, please append to this thread.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...