Form quantity checking

javascript United Kingdom
  • 18 years ago

    I am currently working on a site with a basic shopping cart facility. I have very little knowledge of javascript.


    On selecting items from a form, the details are passed to the partsorder page and for is checked for qauntity selected. I am passing three cart parameters partcode, itemcode+description and qunatity.


    the checking routine below returns an error  'subscript out of range 'i' this only happens if only 1 item is selected to purchase, 2 or more items and the routines work correctly, its doing my head in, can anyone help.


    regards


    Andy Sears email me


    function checkQty () {
    var intQ
    var intTot = parseInt(document.forms[0].TotalOrders.value, 10)


       for (i=0;i<intTot;i++) {
       intQ = parseInt(document.forms[0].elements[(i5)+11+5].value, 10)
           if (! intQ && intQ != 0) {
           alert("Please ensure a numerical value is added.")
           document.forms[0].elements[(i
    5)+11+5].focus()
           return false;
           }
       }


    }





  • 18 years ago

    i'm trying to get my head round your code, so that i can help you


    could you explain the "(! intQ && intQ != 0)" bit....


    i may be wrong but as far as i can see you're saying "if intQ equals false AND it doesn't equal false".... and i dont understand that :P


    once i  understand it all i'll do my best to help you

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perl - The only language that looks the same before and after RSA encryption.” - Keith Bostic