Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
xmaveric #1
Invintory control by limiting forms with javascript?
I am trying to control how many items a user can order by changing the form
field with JavaScript. This isn't working well. Perhaps someone could tell me
how to code a "go-between" page that would compare the quantity requested with
the number of items in inventory?
I did not program this shopping cart system, but I am stuck with it. I am a
novice at ColdFusion and an struggling to figure this out. Here is the code,
feel free to ask any questions:
displayupdateablecartcontent.cfm
viewcart.cfm<CFSET CartTotal=0>
<CF_ShoppingCart FUNCTION="list" CART="wpf">
<CFSET QtyList = "#ShoppingCart_Qty#">
<CFSET ItemList = "#ShoppingCart_Product#">
<!--- Code to Set Qty to Zero (for Delete link) --->
<!--- javascript:document.cart.Qty#ListElement#.value=0; --->
<script language="JavaScript1.1">
<!--
function setFieldValue(oField, iValue){
oField.value = iValue
}
//-->
</script>
<CFOUTPUT>
<table border="0" width="400" cellspacing="0" cellpadding="4" align="center"
class="boldfont">
<tr valign="bottom">
<td align="left" bgcolor="#tablebgcolor#">Product</td>
<td align="left" bgcolor="#tablebgcolor#">Price</td>
<td align="left" bgcolor="#tablebgcolor#">Sub Total</td>
<td align="left" bgcolor="#tablebgcolor#">Quantity</td>
<td align="left" bgcolor="#tablebgcolor#"> </td>
</tr>
<FORM NAME="cart"
ACTION="updatecart.cfm?newLocation=#URLEncodedForm at('checkout.cfm')#"
METHOD="POST" ENABLECAB="Yes">
<INPUT TYPE="hidden" NAME="NumItemsListed" VALUE="#ListLen(QtyList)#">
</CFOUTPUT>
<CFLOOP INDEX="ListElement" from="1" TO="#ListLen(QtyList)#">
<cfquery name="listProducts" datasource="#dbname#" dbtype="ODBC">
SELECT *
FROM #company#item
WHERE ID = '#ListGetAt(ItemList,ListElement)#'
</cfquery>
<cfif listProducts.RecordCount>
<CFSET ProdQty = "#ListGetAt(QtyList,ListElement)#">
<!--- Check for quantity price-break --->
<cfif ProdQty gte listProducts.qtydiscountqty AND
listProducts.qtydiscountqty gt 0>
<CFSET ProdPrice = listProducts.qtydiscountprice>
<cfelse>
<CFSET ProdPrice = listProducts.price>
</cfif>
<!--- End Price-break check --->
<CFSET CartTotal = Evaluate(CartTotal + (ProdPrice * ProdQty))>
<CFOUTPUT>
<tr valign="top">
<td>#listProducts.name#</td>
<INPUT TYPE="hidden" NAME="Item#ListElement#" VALUE="#listProducts.id#">
<td align="right">#DollarFormat(ProdPrice)#</td>
<td align="right">#DollarFormat(ProdPrice * ProdQty)#</td>
<cfif #ProdQty# GT #listProducts.inventory#>
<td ALIGN="center">1<input type="text" name="Qty#ListElement#"
value="#ProdQty#" size="1"
onmouseover="setFieldValue(document.cart.Qty#ListE lement#,#listProducts.inventor
y#); document.cart.action = 'updatecart.cfm'; document.cart.submit();"></td>
<cfelse>
<td ALIGN="center">2<input type="text" name="Qty#ListElement#"
value="#ProdQty#" size="1"
onChange="setFieldValue(document.cart.Qty#ListElem ent#,this.value);
document.cart.action = 'updatecart.cfm'; document.cart.submit();"></td>
</cfif>
<td ALIGN="right"><A HREF="JavaScript:
setFieldValue(document.cart.Qty#ListElement#,0); document.cart.action =
'updatecart.cfm'; document.cart.submit();">Delete</A></td>
</tr>
</CFOUTPUT>
<cfelse>
<CF_ShoppingCart FUNCTION="remove" ITEM="#ListGetAt(ItemList,ListElement)#"
QTY="#ListGetAt(QtyList,ListElement)#" CART="wpf">
</cfif>
</CFLOOP>
<CFOUTPUT>
<tr valign="top">
<td colspan=2 align="right"><font face="verdana,Arial,Helvetica,sans-serif"
size="2"><B>Order Total </B></FONT></td>
<td align="right"><p><font face="verdana,Arial,Helvetica,sans-serif"
size="2">#DollarFormat(CartTotal)# </font></p></td>
<td colspan=2></td>
</tr>
<!--- Bottom Navigation --->
<tr align="center"><td colspan=5>
<INPUT TYPE="submit" value="Place Order" ></td></tr>
</FORM>
<tr valign="top" align="center">
<td colspan=5>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<FORM ACTION="JavaScript: document.cart.action =
'updatecart.cfm?newLocation=categories%2Ecfm'; document.cart.submit();"
METHOD="POST" ENABLECAB="Yes">
<td><INPUT TYPE ="submit" value="Continue Shopping"></td>
</FORM>
<td> </td>
<FORM ACTION="ClearCart.cfm" METHOD="POST" ENABLECAB="Yes">
<td><INPUT TYPE ="submit" value="Empty Cart"></td>
</FORM>
</tr>
</table>
</td>
</tr>
<!--- End Bottom Navigation --->
</CFOUTPUT>
</TABLE>
updatecart.cfm<cfinclude template="#company#_header.cfm">
<div id="PageContent" align="right"><cfinclude template="cart_menu.cfm"></div>
<p><cfinclude template="displayUpdateableCartContents.cfm"></p>
<cfinclude template="#company#_footer.cfm">
[quote}
<!--- Clear the Cart first --->
<!--- Don't let the browser cache this page. Otherwise we might
be looking at a cached shopping cart which does not reflect
what is truly in the cart. --->
<CFHEADER Name="Expires" Value="#Now()#">
<CFHEADER NAME="pragma" VALUE="no-cache">
<CFAPPLICATION NAME="wpfstore" CLIENTMANAGEMENT="Yes">
<CF_ShoppingCart FUNCTION="clear" CART="wpf">
<!--- Then Re-fill the cart with the updated information --->
<CFINCLUDE TEMPLATE="addtocart.cfm">
[/quote]
clearcart.cfm
addtocart.cfm<!--- Don't let the browser cache this page. Otherwise we might
be looking at a cached shopping cart which does not reflect
what is truly in the cart. --->
<CFHEADER Name="Expires" Value="#Now()#">
<CFHEADER NAME="pragma" VALUE="no-cache">
<CFAPPLICATION NAME="wpfstore" CLIENTMANAGEMENT="Yes">
<CF_ShoppingCart FUNCTION="clear" CART="wpf">
<cflocation url="categories.cfm" addtoken="No">
checkout.cfm<!--- Don't let the browser cache this page. Otherwise we might
be looking at a cached shopping cart which does not reflect
what is truly in the cart. --->
<CFHEADER Name="Expires" Value="#Now()#">
<CFHEADER NAME="pragma" VALUE="no-cache">
<CFAPPLICATION NAME="wpfstore" CLIENTMANAGEMENT="Yes">
<cfquery name="listItems" datasource="#dbname#" dbtype="ODBC">
SELECT *
FROM #company#item
ORDER BY itemorder
</cfquery>
<cfif isdefined('FORM.FieldNames')>
<CFSET NumItems = Form.NumItemsListed>
<!--- Loop through items selected and quantities --->
<CFIF NumItems IS '1'>
<CFSET CartItem = "#FORM.item1#">
<CFSET CartQty = "#FORM.qty1#">
<cfif Evaluate(CartQty) GT '0'>
<CF_ShoppingCart FUNCTION="add" ITEM="#CartItem#" QTY="#CartQty#"
CART="wpf">
</cfif>
<CFELSE>
<cfloop Index="loopcounter" From="1" To="#NumItems#">
<CFSET QtyEval = 'Evaluate(FORM.qty#loopcounter#)'>
<cfif Evaluate(QtyEval) GT '0'>
<CFSET CartItem = "Evaluate(FORM.item#loopcounter#)">
<CFSET CartQty = "Evaluate(FORM.qty#loopcounter#)">
<CF_ShoppingCart FUNCTION="add" ITEM="#Evaluate(CartItem)#"
QTY="#Evaluate(CartQty)#" CART="wpf">
</cfif>
</cfloop>
</cfif>
<CFELSE>
<CF_ShoppingCart FUNCTION="add" ITEM="#item#" QTY="#qty#" CART="wpf">
</CFIF>
<cfif IsDefined("URL.newLocation")>
<cflocation url="#URL.newLocation#" addtoken="No">
<cfelse>
<cfinclude template="ViewCart.cfm">
</cfif>
[quote]
<cfinclude template="#company#_header.cfm">
<div id="PageContent" align="right"><cfinclude template="cart_menu.cfm"></div>
<CFAPPLICATION NAME="wpfstore" CLIENTMANAGEMENT="Yes">
<CFSET CartTotal=0>
<CF_ShoppingCart FUNCTION="list" CART="wpf">
<CFSET QtyList = "#ShoppingCart_Qty#">
<CFSET ItemList = "#ShoppingCart_Product#">
<script language="javascript">
function check_fields() {
if (document.theform.billtofirstname.value=="") {
alert("Please enter your first
name");document.theform.billtofirstname.focus();re turn false
}
if (document.theform.billtolastname.value=="") {
alert("Please enter your last
name");document.theform.billtolastname.focus();ret urn false
}
if (document.theform.billtoaddress.value=="") {
alert("Please enter your
address");document.theform.billtoaddress.focus();r eturn false
}
if (document.theform.billtocity.value=="") {
alert("Please enter your city");document.theform.billtocity.focus();return
false
}
if (document.theform.billtostate.value=="") {
alert("Please enter your
state");document.theform.billtostate.focus();retur n false
}
if (document.theform.billtozip.value=="") {
alert("Please enter your zip");document.theform.billtozip.focus();return
false
}
if (document.theform.ccnumber.value=="") {
alert("Please enter your Credit Card
Number");document.theform.ccnumber.focus();return false
}
}
</script>
<table border="0" cellspacing="0" cellpadding="0" id="PageContent"
class="header1font">
<form name="theform" action="order_send.cfm" method="post" onSubmit="return
check_fields()">
<tr><td>Items Ordered:</td></tr>
</table>
<!--- Customized Information/Cart Display --->
<cfset iNumberOfCartItems = 0>
<CFLOOP INDEX="ListElement" from="1" TO="#ListLen(QtyList)#">
<cfquery name="listProducts" datasource="#dbname#" dbtype="ODBC">
SELECT *
FROM #company#item
WHERE ID = '#ListGetAt(ItemList,ListElement)#'
</cfquery>
<CFSET ProdQty = "#ListGetAt(QtyList,ListElement)#">
<!--- Check for quantity price-break --->
<cfif ProdQty gte listProducts.qtydiscountqty AND listProducts.qtydiscountqty
gt 0>
<CFSET ProdPrice = listProducts.qtydiscountprice>
<cfelse>
<CFSET ProdPrice = listProducts.price>
</cfif>
<!--- End Price-break check --->
<CFSET CartTotal = #Evaluate(CartTotal + (ProdPrice * ProdQty))#>
<CFOUTPUT>
<!--- If there are multiple products and multipleform is True, supply a
custom form for each product ordered --->
<cfif listProducts.multipleform>
<cfset iMaxElementNumber = ProdQty - 1>
<cfloop index="El
xmaveric Guest
-
Forms and Javascript
HI, Im working on a page that give directions to an event. the event has multipul locations, though. im trying to use a mapquest form that is... -
Limiting number of control instances?
Hey all, Is there a way of limiting the number of instances of a server control that the user can put on a form? I'm writing an interfaceless... -
Javascript and forms HELP!!!!!
Guys, I have no knowledge of javascript at all, but I need to make a form which will validate fields using javascript and then submit the data to a... -
output text in control location; calling control javascript from page javascript
Hi; If you don't know, I'm just learning javascript and aspnet, but I have a pretty good grounding in windows programming. I'm trying to build a... -
Limiting radio buttons with Javascript
Hello all, I have a very large form, and one of the sections in the form is a group of about 14 checkboxes. I would like to limit the number of... -
-
dempster #3
Re: Invintory control by limiting forms with javascript?
You can use JavaScript to program a maximum allowable value in an input field,
using the onChange or onSubmit event handler to check this (and check that it
is a number). You can use ColdFusion on the server to get the available
quantity and set this max value in the page that is sent to the user.
Once an order is submitted, you'd need to check on the server again in case
the inventory changed (also, you should never rely only on JavaScript to
validate or check data). If the quantity is not available, you'll have to
return a page with that error message and the maximum value for the JavaScript
checking.
-Paul
dempster Guest



Reply With Quote

