How to do validation

Discussion in 'PHP' 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.



    <body>
    <script language="javascript1.2">
    function verify(form)
    {
    if(form.my.value=="")
    {
    alert("please fill");
    document.form.my.focus();
    return(false);
    }
    if(form.my2.value=="")
    {
    alert("please fill the right value");
    document.form.my2.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. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    This should be in the Javascript section.
     
    nico_swd, Feb 23, 2008 IP
  3. Ares

    Ares Member

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #3
    try :

    onchange
     
    Ares, Feb 23, 2008 IP