CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: validation

  1. #1
    Join Date
    Mar 2005
    Location
    India
    Posts
    102

    Angry validation

    If the user doesn't provide the name , an alert box should be displayed and the text box should get focus
    And I want to perform the validation before going to the next page(log.asp),i.e before the log.asp page gets displayed.
    I have used document.frm.txtbox_name.focus(); ,but that doesn't work

    Can anyone help me with this?
    <html>
    <head>
    <script language="JavaScript">

    function show()
    {

    if (document.frm.txtbox.value=="")
    {
    window.alert("enter name");
    document.frm.txtbox.focus();
    }

    }

    </script>
    </head>
    <body>
    <form name="frm" method="post" action="log.asp">
    Name:
    <input type="text" name="txtbox">

    <input type="Submit" value="Enter Name" onClick="show()">


    </form>

    </body>
    </html>

    Regards
    Manjula
    ------------
    "To err is Human, and to blame it on a computer is even more so.."

  2. #2
    Join Date
    May 2004
    Location
    MN / NJ, United States
    Posts
    768

    Re: validation

    Your form tag should be:
    HTML Code:
    <form ... onsubmit="return show()">
    Your show() function should be:
    Code:
    function show() {
      if(document.frm.txtbox.value=="") {
        alert("enter name");
        document.frm.txtbox.focus();
        return false;
      }
      return true;
    }
    Dr. Script
    *9-11-01* Never Forget; Never Forgive; Never Relent!
    "If we ever forget that we're one nation under God, then we will be a nation gone under." - Ronald Reagan

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

Featured