Results 1 to 3 of 3

Thread: how to make submit event run after execution my function

  1. #1
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default how to make submit event run after execution my function

    hello....
    can anyone here tell me, HOW to make "submit event" on form run after it executes my function?

    please see the example below...

    <form name="myform" action="login.php" method="post" onsubmit="checking_valid_then_checking_ajax()">
    <input type="text" name="u">
    <imput type="password" name="p">
    <input type="submit" value="submit">
    </form>


    then the function is below..

    function checking_valid_then_checking_ajax(){
    if(document.myform.u=="" || document.myform.p==""){
    alert('please complete form!');
    return false;
    }
    cheking_ajax();
    }

    base on the function above, if the user doesnt enter his username and apssword during submitting the form, of course "submiting activity by the form" will be stop.

    BUT, if all ok, function will continue to excute "checking_ajax()".

    HERE is my problem,

    before my code finish its job to execute "checking_ajax()", the "submit event" is still running... so before my checking_ajax() executed, the form has redirected the page to login.php

    WHAT i want is, stop "submit event" first, then finish cheking_ajax(), and after "cheking_ajax" return the value "OK", run "submit event" again.

    anyone?
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You will have no control over the submit action unless the onsubmit event returns true or false. So, to begin with you should do this:

    Code:
    onsubmit="return checking_valid_then_checking_ajax();"
    Now, let's look at what happens in your function. If u or p are empty, it returns false. Otherwise it hands over to cheking_ajax() and returns undefined. I can't see what cheking_ajax() does. It should be setup to return true or false, ex:

    Code:
    function cheking_ajax(){
    if (something)
    return true;
    alert('no ajax');
    return false;
    };
    or:

    Code:
    function cheking_ajax(){
    if (something){
    alert('no ajax');
    return false;
    }
    return true;
    };
    If it is like one of those (the alerts are optional), then your checking_valid_then_checking_ajax() function can be:

    Code:
    function checking_valid_then_checking_ajax(){
    if(document.myform.u=="" || document.myform.p==""){
    alert('please complete form!');
    return false;
    }
    return cheking_ajax();
    }
    and it should all work out. But your cheking_ajax() may hand off to yet another function, if it does, then it must return a value of true or false as derived from that function.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default That what i want !

    HI, yes....i got it, i totally understand what you wrote!,

    thanks very much, i never think about "onsubmit="return checking_valid_then_checking_ajax()"

    NICE TO MEET YOU
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •