Second form validation problem

Discussion in 'ASP General' started by John, Jul 9, 2006.

  1. John

    John Guest

    Hi

    I have two forms on my page. Both use javascript to validate input before
    submission. Problem is that first form does the validation fine but the
    second form gets submitted without any validation taking place. Simplified
    form of code is given below.

    What am I doing wrong?

    Thanks

    Regards


    <html>
    <head>

    <script type="text/javascript">
    // <![CDATA[
    function validate()
    {
    // validation code here, which works fine
    }

    function valid1()
    {
    f=document.getElementById("Form1");
    if(f.StaffCode.value<>"HS01")
    {
    alert("Invalied code. Please re-enter.");
    f.StaffCode.focus();
    return false;
    }
    }

    // ]]>
    </script>

    </head>
    <body>
    <!--This form validates fine using function validate-->
    <form id="theform" method="post" action="abc.asp" onsubmit="return
    validate();">
    <input type="hidden" name="mode" value="1">
    <input type="text" name="muser" id="muser" value="" size="20">
    <input type="password" name="mpass" id="mpass" value="" size="20">
    <input name="bu_submit" type="image"
    src="images/box/bu_login_sm.gif" border="0"
    class="noborder" style="height: 31px;">
    </form>

    <!--This form does not validate using function valid1-->
    <form id="Form1" method="post" action="xyz.asp" onsubmit="return
    valid1();">
    <input type="text" name="StaffCode" id="StaffCode" value=""
    size="30">
    <input name="bu_submit" type="image" src="images/box/bu_login.gif"
    border="0" class="noborder"
    style="height: 31px;">
    </form>
    </body>
    </html>
     
    John, Jul 9, 2006
    #1
    1. Advertising

  2. John

    Mike Brind Guest

    John wrote:
    > Hi
    >
    > I have two forms on my page. Both use javascript to validate input before
    > submission. Problem is that first form does the validation fine but the
    > second form gets submitted without any validation taking place. Simplified
    > form of code is given below.
    >
    > What am I doing wrong?
    >


    If you want to know what's wrong with your javascript, you should post
    to a javascript group - microsoft.public.scripting.jscript, for
    example.

    But client side validation is not recommended. It does not work for
    those with javascript disabled, or those that want to get round it.
    And having acceptable log in values accessible to all through View
    Source rather defeats the whole point. You should move to server-side
    validation.

    --
    Mike Brind
     
    Mike Brind, Jul 9, 2006
    #2
    1. Advertising

  3. John

    John Guest

    Thanks. I just want a way to validate the second form and not necessarily
    via javascript. Any help would be appreciated. The validation required is
    not fort Knox standard though, just to deter a casual user.

    Thanks

    Regards

    "Mike Brind" <> wrote in message
    news:...
    >
    > John wrote:
    >> Hi
    >>
    >> I have two forms on my page. Both use javascript to validate input before
    >> submission. Problem is that first form does the validation fine but the
    >> second form gets submitted without any validation taking place.
    >> Simplified
    >> form of code is given below.
    >>
    >> What am I doing wrong?
    >>

    >
    > If you want to know what's wrong with your javascript, you should post
    > to a javascript group - microsoft.public.scripting.jscript, for
    > example.
    >
    > But client side validation is not recommended. It does not work for
    > those with javascript disabled, or those that want to get round it.
    > And having acceptable log in values accessible to all through View
    > Source rather defeats the whole point. You should move to server-side
    > validation.
    >
    > --
    > Mike Brind
    >
     
    John, Jul 9, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?YzY3NjIyOA==?=

    how to pass value from first form to second form?

    =?Utf-8?B?YzY3NjIyOA==?=, Jan 11, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    891
    =?Utf-8?B?YzY3NjIyOA==?=
    Jan 11, 2006
  2. John

    Second form validation problem

    John, Jul 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    337
    Chagel
    Jul 9, 2006
  3. bnp
    Replies:
    4
    Views:
    344
  4. yelipolok
    Replies:
    4
    Views:
    282
    John W. Krahn
    Jan 27, 2010
  5. Replies:
    5
    Views:
    113
Loading...

Share This Page