Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

form validation

Options
  • 02-12-2008 3:46pm
    #1
    Closed Accounts Posts: 184 ✭✭


    Anyone know of an easy to validate a form using javascript?


Comments

  • Registered Users Posts: 180 ✭✭marcphisto




  • Closed Accounts Posts: 184 ✭✭vodkadub


    Im looking for something hand coded, thanks anyway


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    There really isn't a way to use javascript for form validation unless is server side javascript.


  • Moderators, Category Moderators, Motoring & Transport Moderators Posts: 21,238 CMod ✭✭✭✭Eoin


    As Evil Phil says, server side is the place to do it. Doing it client side should only be for the purposes of usability, and not relied on by the site.

    That said, here's a quick example you can work from:
    [html]
    <script type="text/JavaScript">
    function checkForm()
    {
    if (document.getElementById("txtName").value == "")
    {
    alert("Please enter your name");
    return false;
    }
    return true;
    }
    </script>
    <form name="frmTest" action="this.asp" method="post" onsubmit="return checkForm()">
    Name: <input type="text" name="txtName" id="txtName" value="" />
    <input type="submit">
    </form>
    [/html]


Advertisement