Newbie - what is my problem?

Discussion in 'ASP General' started by M. Noroozi Eghbali, Nov 18, 2004.

  1. Hi,

    In the asp file, I have a form and a validation function. The message box
    opens while validating, but the form action is activated when the validating
    is false. I could not find the problem. Any body can help me?

    Here is the code:
    ----------------------------------
    <script language="vbscript">
    function Validator()
    dim Result
    Result = true
    if len(document.InfoForm.T1.value) < 2 then
    msgbox("Please enter your full name")
    document.InfoForm.T1.focus
    Result = false
    end if
    Validator = Result
    end function
    </script>

    <form method="POST" name="InfoForm" onsubmit="return Validator()">
    <input type="text" name="T1" size="32">
    <input type="submit" value="Download" name="B1">
    </form>
    ----------------------------------

    Thank you,
    Mehrdad
    M. Noroozi Eghbali, Nov 18, 2004
    #1
    1. Advertising

  2. M. Noroozi Eghbali wrote:
    > Hi,
    >
    > In the asp file, I have a form and a validation function. The message
    > box opens while validating, but the form action is activated when the
    > validating is false. I could not find the problem. Any body can help
    > me?
    >
    > Here is the code:
    > ----------------------------------
    > <script language="vbscript">
    > function Validator()
    > dim Result
    > Result = true
    > if len(document.InfoForm.T1.value) < 2 then
    > msgbox("Please enter your full name")
    > document.InfoForm.T1.focus
    > Result = false
    > end if
    > Validator = Result
    > end function
    > </script>
    >
    > <form method="POST" name="InfoForm" onsubmit="return Validator()">
    > <input type="text" name="T1" size="32">
    > <input type="submit" value="Download" name="B1">
    > </form>
    > ----------------------------------
    >
    > Thank you,
    > Mehrdad


    This is not an asp problem (you could reproduce this problem with a .htm
    file could you not?). ASP is server-side code and you are asking about
    client-side behavior. Please follow up in the .scripting.vbscript newsgroup,
    or one of the groups with "dhtml" in their names.

    I need to know how you've determined that validator() is returning False.
    You should put a msgbox statement in your function to verify this:

    msgbox Result

    If it is returning the correct value, then try

    window.event.returnValue = False

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Nov 18, 2004
    #2
    1. Advertising

  3. Thank you Bob. I set the window.event.returnValue to False and now the
    script works fine. I excuse all for sending the message to a wrong group.

    Thank you again,
    Mehrdad



    "Bob Barrows [MVP]" <> wrote in message
    news:...
    > M. Noroozi Eghbali wrote:
    > > Hi,
    > >
    > > In the asp file, I have a form and a validation function. The message
    > > box opens while validating, but the form action is activated when the
    > > validating is false. I could not find the problem. Any body can help
    > > me?
    > >
    > > Here is the code:
    > > ----------------------------------
    > > <script language="vbscript">
    > > function Validator()
    > > dim Result
    > > Result = true
    > > if len(document.InfoForm.T1.value) < 2 then
    > > msgbox("Please enter your full name")
    > > document.InfoForm.T1.focus
    > > Result = false
    > > end if
    > > Validator = Result
    > > end function
    > > </script>
    > >
    > > <form method="POST" name="InfoForm" onsubmit="return Validator()">
    > > <input type="text" name="T1" size="32">
    > > <input type="submit" value="Download" name="B1">
    > > </form>
    > > ----------------------------------
    > >
    > > Thank you,
    > > Mehrdad

    >
    > This is not an asp problem (you could reproduce this problem with a .htm
    > file could you not?). ASP is server-side code and you are asking about
    > client-side behavior. Please follow up in the .scripting.vbscript

    newsgroup,
    > or one of the groups with "dhtml" in their names.
    >
    > I need to know how you've determined that validator() is returning False.
    > You should put a msgbox statement in your function to verify this:
    >
    > msgbox Result
    >
    > If it is returning the correct value, then try
    >
    > window.event.returnValue = False
    >
    > Bob Barrows
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    >
    >
    M. Noroozi Eghbali, Nov 18, 2004
    #3
  4. M. Noroozi Eghbali

    G Guest

    Take the onsubmit event off of the <form> tag and put an onClick event on
    the <input type=submit onClick="return Validator();"> tag.

    Also, you should use JavaScript for client-side scripts. VBScript is
    limited to IE only.

    Glenn


    "M. Noroozi Eghbali" <> wrote in message
    news:...
    > Hi,
    >
    > In the asp file, I have a form and a validation function. The message box
    > opens while validating, but the form action is activated when the
    > validating
    > is false. I could not find the problem. Any body can help me?
    >
    > Here is the code:
    > ----------------------------------
    > <script language="vbscript">
    > function Validator()
    > dim Result
    > Result = true
    > if len(document.InfoForm.T1.value) < 2 then
    > msgbox("Please enter your full name")
    > document.InfoForm.T1.focus
    > Result = false
    > end if
    > Validator = Result
    > end function
    > </script>
    >
    > <form method="POST" name="InfoForm" onsubmit="return Validator()">
    > <input type="text" name="T1" size="32">
    > <input type="submit" value="Download" name="B1">
    > </form>
    > ----------------------------------
    >
    > Thank you,
    > Mehrdad
    >
    >
    G, Nov 18, 2004
    #4
    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. Id0x
    Replies:
    4
    Views:
    1,170
    Erik Max Francis
    Jul 21, 2003
  2. JohnE

    newbie with newbie questions

    JohnE, Aug 17, 2009, in forum: ASP .Net
    Replies:
    3
    Views:
    483
    Gregory A. Beamer
    Aug 17, 2009
  3. Jerry C.
    Replies:
    8
    Views:
    207
    Uri Guttman
    Nov 23, 2003
  4. Kruno Saho
    Replies:
    0
    Views:
    125
    Kruno Saho
    Apr 7, 2013
  5. Dave Angel
    Replies:
    0
    Views:
    110
    Dave Angel
    Apr 7, 2013
Loading...

Share This Page