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

  • SEARCH
  • Home
  • 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 8560009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:10:53+00:00 2026-06-11T16:10:53+00:00

Hi below I have a submit button and a jquery function it performs when

  • 0

Hi below I have a submit button and a jquery function it performs when the submit button is clicked on:

<p><input id="submitBtn" name="submitDetails" type="submit" value="Submit Details" onClick="return myClickHandler();" /></p>

<script type="text/javascript"> 
function myClickHandler()
{
     if (validation())
     {
         showConfirm();
         return true;
     }

     return false;
}
</script>

Now as you can see if the validation() function is met, then it will perform the showConfirm() function and this function will perform the confirmation box which is below:

function showConfirm()
{
    var confirmMsg=confirm("Make sure that your details are correct, once you proceed after this stage you would not be able to go back and change any details towards Questions, Options and Answers for your Assessment." + "\n" + "\n" + "Are you sure you want to Proceed?" + "\n" );

    if (confirmMsg == true)
    {
        submitform(); 
        return true;  
    }
    else
    {
        return false;
    }
}

function submitform()
{
    var fieldvalue = $("#QandA").val();
    $.post("insertQuestion.php", $("#QandA").serialize(), function(data)
    {
        var QandAO = document.getElementById("QandA");
        QandAO.submit();
    });  
    alert("Your Details for this Assessment has been submitted"); 
}

My question is this. If the user clicks on OK in the confirmation box, then it submits the page which is fine. But if the user clicks on Cancel, then it should not submit the page. The problem is that it is submitting the page even though the Cancel button has been clicked on. Why is this?

UPDATE:

I have tried this code below but still no luck:

function myClickHandler()
{
     if(validation())
     {
         return showConfirm();
     }

     return false;
}
  • 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-06-11T16:10:54+00:00Added an answer on June 11, 2026 at 4:10 pm
    if(validation()){
        showConfirm();
        return true;
    }
    

    You don’t do anything with the return from showConfirm();. You just return true after that function is done. Try return showConfirm();.


    If the user clicks Cancel in the showConfirm() function, then it does not execute the submitform() function, and the showConfirm() function returns false. But since you don’t capture that return value, the myClickHandler() function returns true, which doesn’t prevent the form from being submitted.

    You probably just want the myClickHandler() function to always return false, and let the form submission be handled by your showConfirm() function.


    UPDATE:
    Here is a (IMO) better way. I’m not sure that you need to use AJAX (the $.post call) at all. Try this:

    <form id="QandA" action="somepage.php" method="POST" onsubmit="return myClickHandler()">
        <!--
            ...
        -->
        <input type="submit" id="submitBtn" name="submitDetails" value="Submit Details" />
    </form>
    
    <script type="text/javascript">
        function myClickHandler()
        {
            if (!validation())
                return false;
    
            if (!confirm("Make sure that your details are correct, once you proceed after this stage you would not be able to go back and change any details towards Questions, Options and Answers for your Assessment." + "\n" + "\n" + "Are you sure you want to Proceed?" + "\n" ))
                return false;
    
            // if all you're trying to do is submit the form to insertQuestion.php,
            // then skip this AJAX call. I'm assuming that you need to do something
            // on the server before submitting the form. if not, skip this.
            $.ajax({
                url: "insertQuestion.php",
                data: $("#QandA").serialize(),
                async: false
            });
    
            return true;
        }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form to 'create a tag'. Using the jQuery code below. $(#createtag).submit(function()
I have the following HTML <form id=create_form name=create_form action= method=post> <input name=type id=type value=individuel
Below I have table - Company id name value year 1 IBM 10 2011
I have a form which has a input textbox and submit button. On submission
I have a button in a jQuery tabbed page declared like this: <input id=buttonSave
I have the below form that i want to remove the submit button from
Ajax-returned HTML includes a table and a submit button (type=button) The table includes jQuery
i load a form into a jquery ui dialog. i have a submit button
I have a form where i've replaced the submit button with an input (with
I have a html page that allows users to submit a file. Below is

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.