Invintory control by limiting forms with javascript?

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default 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
    <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#">&nbsp;</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>&nbsp;&nbsp;&nbsp;&nbsp;</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>
    viewcart.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">
    updatecart.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
    <!--- 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">
    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">
    <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>
    checkout.cfm
    [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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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...
    5. 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...
  3. #2

    Default Re: Invintory control by limiting forms with javascript?

    *bump*
    xmaveric Guest

  4. #3

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139