Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 766823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T17:06:36+00:00 2026-05-14T17:06:36+00:00

If the submit button is clicked, prevent the default action and see if the

  • 0

If the submit button is clicked, prevent the default action and see if the field ‘account_name’ is already in use. If the $.get() returns a result, alert the user of the results. If it doesn’t, submit form with id="add_account_form".

My problem is that my else{} statement is not submitting the form. I get no response when submit is clicked & there is no value returned.

Also I would like to change my code where it goes $("#add_account_form").submit(..) instead of .click() however, would that cause a problem when trying to submit the form later in the script?

    <script type="text/javascript">
        $(document).ready( function () { 

            $("#submit").click( function () { 
                 var account_name = $("input[name=account_name]").val();
                    $.get(
                        "'.url::site("ajax/check_account_name").'", 
                    {account_name: account_name}, 
                    function(data){ 
                        if(data.length > 0){            
                                    confirm( "The account name you entered looks like the following:\n"
                                                        +data+
                                            "Press cancel if this account already exists or ok to create it."
                                                ); 
                        }else{
                            $("#add_account_form").submit();
                        }                   
                    });
                    return false;                
                });
            });
    </script>
                                                    <p>
                                                        <input type="submit" id="submit" class="submit small" name="submit" value="Submit" />
                                                    </p>
                                                </form> 

Thanks for your help.

EDIT

So anyone who runs into my problems, it’s that $.get() is asynchronous, so it will always return false, or true depending on what submitForm is defined as. $.ajax() however, allows async to be set as false, which allows the function to finish before moving on. See what I mean:

        $(document).ready( function () {                                
            $("#add_account_form").submit( function () { 
                var submitForm = true;
                 var account_name = $("input[name=account_name]").val();
                    $.ajax({
                        type: "GET",
                        async: false,
                        url: "'.url::site("ajax/check_account_name").'", 
                        data: ({account_name: account_name}), 
                        success:
                    function(data){ 
                        if(data.length > 0){            
                                    if(!confirm( "The account name you entered looks like the following:\n"
                                                        +data+
                                                        "Press cancel if this account already exists or ok to create it."
                                                )){ 
                                                submitForm = false;
                                            }
                        }   
                    }
                    });

                        if (submitForm == false ) {
                    return false;     
                        }

                });
            });

Thanks for your help @Dan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T17:06:37+00:00Added an answer on May 14, 2026 at 5:06 pm

    Taking a bit of a guess, but perhaps data.length is always true?

    I’d try returning a boolean or just a bit.

    then:

    if(data) {
      confirm();
    } else {
      $('#form-id').submit();
    }
    

    Hope that helps 🙂

    EDIT: Mis-read question

    What may be happening is when the submit button is clicked, the form submits after the click. In other words, you may have to have a form.submit event caught:

    $('form').submit(function() {
        var submitForm = true;
        var account_name = $("input[name=account_name]").val();
        $.get(
            "'.url::site("ajax/check_account_name").'", 
        {account_name: account_name}, 
        function(data){ 
            if(data.length > 0){
                if (!confirm("The account name you entered looks like the following:\n"
                            +data+
                            "Press cancel if this account already exists or ok to create it."
                            )) {
                    submitForm = false;
            }                   
        });
        if (!submitForm) {
            return false;                
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.