Results 1 to 5 of 5

Thread: Pls Help. How to cancel a form submit with vbscript.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769

    Pls Help. How to cancel a form submit with vbscript.

    I have a form with a submit button. I want to perform some checking before submitting the form. How do i cancel a submit after the user has clicked the button?

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    try to run the validation code thru:

    <form method="POST" action="register.cgi" onSubmit="runsomething>

    get it?

  3. #3
    Hyperactive Member progressive's Avatar
    Join Date
    Sep 2001
    Location
    Manchester, UK
    Posts
    404
    You can do it with javascript !


    Code:
    <script language="javascript">
    
    function myValidateRoutine(my_form){
    
        //do my form validation
    
    }
    
    </script>
    
    <form method="POST" action="register.cgi" onSubmit="myValidateRoutine(this.form); return false;">

  4. #4
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    Shouldn't that be:

    <script language="JavaScript">

    function Validate(frmName){

    //Check data here

    if(good_data){
    //if the data is good return true
    return true;
    }

    else
    //no good
    return false;

    }//end function

    </script>

    <form METHOD = "post" onSubmit="return Validate(this);">

    Wouldn't the way you have it written cancel it anyway?
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

  5. #5
    Hyperactive Member progressive's Avatar
    Join Date
    Sep 2001
    Location
    Manchester, UK
    Posts
    404
    Yes your right it would cancel it but the form would be submitted by javascript from within the function if the validation is ok.

    When you submit the form using javascript it by-passes the onSubmit atrribute of the form.

    Either way doesn't matter you just need to have a false value in there. Othewise it will try to go to the script in the action attribute of the form.

    I like the way you did it though

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