Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

form validation

  • 02-12-2008 03:46PM
    #1
    Closed Accounts Posts: 184 ✭✭


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


Comments

  • Registered Users, Registered Users 2 Posts: 180 ✭✭marcphisto




  • Closed Accounts Posts: 184 ✭✭vodkadub


    Im looking for something hand coded, thanks anyway


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


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


  • Registered Users, Registered Users 2 Posts: 21,278 ✭✭✭✭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