Results 1 to 5 of 5

Thread: Stopping a form from submitting with VBSCript

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2002
    Posts
    42

    Stopping a form from submitting with VBSCript

    I am trying to run a Validation function that is called when the submit button is clicked. The function checks the defined restrictions on the form, and if there is an error found, sets the status variable to 1. If there are not errors, the Status variable stays a 0. this is the next if statement I have:

    IF Status = "0" THEN
    document.form.submit()
    ELSE
    return false
    END IF

    the return false should stop the form from submitting. This is a JavaScript function, but I thought I was the same in VBScript, but unfortunately, the form still dispalys the errors, but also submits. Does anyone know how to keep a form from not submitting?

    Steve

  2. #2
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    First of all, is the button's type 'submit' or 'button'? If it is of type submit, I doubt that your form validation is even working. You should have the button's type be 'button' and call the JavaScript function from the button's OnClick event.
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  3. #3
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    Also your if statement is incorrect in javascript. Another thing to consider is what type of value has been passed to and stored in Status? You are doing a string comparison, if you passed a number to the variable, this would also cause your if ... then not to work properly.
    Code:
    if (Status=="0")
    {
         document.form.submit() ;
         return true;
    }
    else
    {
         return false;
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2002
    Posts
    42
    No, my validation if statements are working fine. I receive every message when I should. I was using the onclick function and the problem was that when you clicked the enter key, the form was submitting without hitting the button hense, no validation. I had to use the onsubmit. and you are right, my if statements are not Javascript, but VBScript. I would like to stay with VBScript so all I am asking is if someone knows the correct return false statement in VBScript. Thanks though.

    Steve

  5. #5
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by warker
    . I would like to stay with VBScript so all I am asking is if someone knows the correct return false statement in VBScript. Thanks though.

    Steve
    Hi Steve,
    You shouldnt use vbscript on client side, but since you are adament here is how you can validate a form using VBScript.

    Hope this helps

    Danial

    VB Code:
    1. <HTML>
    2. <HEAD>
    3. <TITLE></TITLE>
    4. <script language=vbscript>
    5. function validate()
    6.     if test.text1.value="" then
    7.         msgbox "Please enter a value"
    8.         Window.event.returnValue = false
    9.     end if
    10. end function
    11. </script>
    12. </HEAD>
    13.  
    14. <Form name=test onsubmit="validate()">
    15.  
    16. <input type=text name=text1>
    17. <input type=submit>
    18.  
    19. </BODY>
    20. </HTML>
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

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