javascript validation

Discussion in 'JavaScript' started by kharearch, Feb 23, 2008.

  1. #1
    I am doing length validation but it's not working. For this I am using onBlur event but it is not working. Please help me how to do it. I think it is not firing onBlur event.

    My code is following -

    <body>
    <script language="javascript1.2">
    function verify(form)
    {
    if(form.my.value=="")
    {
    alert("please fill");
    document.form.my.focus();
    return(false);
    }
    }

    function checklen(form)
    {
    val = form.my.value;
    len=val.length;
    alert("writwe value");
    if(len>10)
    {
    alert("value exceeds 10 character");
    form.my.value="";
    form.my.focus();
    }
    }


    </script>
    <form name="form" method="post" onSubmit="return verify(this)" action="validation2.php">
    <p>
    <input type="text" name="my" onBlur="checklen(this)">
    </p>
    <p>
    <input type="text" name="my2">
    </p>
    <p> <input type="submit" name="Submit" value="Submit" >
    </p>
    </form>
    </body>
     
    kharearch, Feb 23, 2008 IP
  2. 2WDH.com

    2WDH.com Active Member

    Messages:
    143
    Likes Received:
    3
    Best Answers:
    5
    Trophy Points:
    68
    #2
    Hi Kharearch.

    Rename your form to something different (name="myform" instead of name="form" for example), change it in your javascript code correspondingly and that should resolve your issue.
     
    2WDH.com, Feb 23, 2008 IP