Results 1 to 2 of 2

Thread: client side check

  1. #1

    Thread Starter
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    Try this : -

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Check Form Client Side</title>
    <script language="JavaScript" type="text/javascript">
    <!--
    function checkForm(form){
    for (var i = 0; i < form.elements.length; i++) {
    var objectID = form.elements[i];
    if (objectID.type == 'text' || objectID.type == 'textarea' || objectID.type == 'password' || objectID.type == 'file' ) {
    if (objectID.value == '') {
    alert('Please fill out the text field ' + objectID.name);
    objectID.focus();
    return false;
    }
    }
    }
    }
    //-->
    </script>

    </head>
    <body>
    <form name="form1" method="POST" action="process.asp" onsubmit="return checkForm(this)">
    <input type="text" name="sometext">
    <input type="password" name="somemoretext">
    <input type="submit" value="Go!">
    </form>
    </body>
    </html>

    It checks the form to see if the text boxes contain text and if it returns false it wont let you continue.
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

  2. #2
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    Client-side error checking is great for the user because they can get quick feed-back without having to wait on a server response. It is often wise, however, to put similar checking on the server-side anyway for security purposes. That way, a malicious hacker will have a more difficult time screwing things up, should one decide to "play" with your html and JavaScripts.

    cudabean

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width