SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript Error Checking Problem

    Hi,

    On my web page, I have a few products displayed.
    Beside each product is an inputbox called "quantity" and beside that
    a image called "submit". I have wrapped each product in a new form.

    My code works to check if the quantity field doesn't meet certain parameters, but if you click the "submit" image, it doesn't check the value of the quantity box. How do I fix this?

    Input code & Image code

    <input type="text " name="quantity" class="TableOutline" size="2" maxlength="3" onblur="CheckQuantity(this, 'Form_SSG001')">

    <input type="image" src="images/submitme.jpg" border="0" name="submit" onClick="CheckQuantity(this, 'Form_SSG001')">

    Below is my Javascript code:

    function CheckQuantity(inp, form)
    {
    var bIsValid = true;
    var sTemp1 = (eval ("document." + form + ".quantity" + ".value"));

    if (sTemp1 == "")
    {
    inp.value = "";
    bIsValid = false;
    return bIsValid;
    }
    else if ((sTemp1 >= 10) && (sTemp1 < 990))
    {
    inp.value = "";
    bIsValid = true;
    return bIsValid;
    }
    else
    {
    alert ("Participant Guides are available in quantities of 10 or more. Please enter a minimum quantity of 10.");
    bIsValid = false;
    return bIsValid;
    }
    }

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    The onclick event needs to have returned to it the value from the function.

    onClick="return CheckQuantity(this, 'Form_SSG001')"
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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