Form validation help!

Discussion in 'JavaScript' started by madmax728, Apr 11, 2008.

  1. #1
    http://www.pratee.com/reg

    Now I am checking for incorrect values, such as space in name or incorrect email ID using PHP. I have seen many people do it with Javascript. I did try making one and I got it right, but the validation onsubmit is not working, so I removed it. Can someone suggest a script for validation on submit?
     
    madmax728, Apr 11, 2008 IP
  2. sunder

    sunder Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can also do it on the fly, not only at the point where the user submits the form.

    You need to have a Java Function that makes all the checks on the form, and then call it from the form.

    For checkbox and radio, use onClick.
    For text field and textarea use onkeyUp
    foe select drop-downs use onChange and call this function whenever the user changes something.

    A small example would be:

    <script type="text/javascript">
    function SubButIf()
    {
    x1 = document.getElementById("xuser");
    x2 = document.getElementById("xpassword");

    if (x1.value.length >= 1 && x2.value.length >= 1)
    {
    ***do something, e.g. submit form***
    }
    else
    {
    *** since either username or password is empty do not submit but display an alert or something ****
    }
    }
    </script>

    and then the form:
    <form method="POST" action="formsubmit.php">
    <input type="text" name="xuser" id="xuser" size="20" onkeyUp="SubButIf()">
    <input type="password" name="xpassword" id="xpassword" size="20" onkeyUp="SubButIf()">
    <input type="submit" value="submit form">
    </form>


    You can extend this to any point you'd like, or add any plus checks.
     
    sunder, Apr 12, 2008 IP
  3. temp2

    temp2 Well-Known Member

    Messages:
    1,231
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    150
    Digital Goods:
    2
    #3
    you can find many validation scriptf at here
     
    temp2, Apr 12, 2008 IP