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 8765011
In Process

The Archive Base Latest Questions

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

I have <a href=url onclick=var msg = confirm(‘Confirm?’); submit(msg, event);>Click me</a> What I want

  • 0

I have

<a href="url" onclick="var msg = confirm('Confirm?'); submit(msg, event);">Click me</a>

What I want to do is take the confirmation box result (true/false), pass it to the submit button, and then kill the href call if its false.

I have it working in my development environment, but when I load this into a cross browser scenario, the second call isn’t working:

function submit(msg, evt) {

     if(msg == true) {
         $.ajax({
             type:"POST",
             data:{answer:'Correct'},
             url:'https://myurl/p'
          });
     }
     else { evt.preventDefault(); return false; }
}

The URL passed is just the URL and has no data to it (in production). This exact code works perfectly fine in my environment, but in the cross browser scenario it fails. If I remove the confirmation box, everything works perfectly.

I have a feeling it’s tied to the preventDefault call on the cancel of the confirmation box. Would that preventDefault disable the next call out with that same link?

  • 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-13T16:10:48+00:00Added an answer on June 13, 2026 at 4:10 pm

    First of all, please don’t use inline event handlers, you can remove this from the markup and deal with it in your js where it belongs:

    HTML:

    <a href="url" id="myanchor">Click me</a>
    

    JS:

    anchor = $('#myanchor')[0];
    anchor.on('click',function(){
        var msg = confirm('Confirm?'); 
        submit(msg, event);
    });
    

    Secondly, if msg is true the ajax call is immediately interrupted by a page redirect, which doesn’t make much sense. I believe you want the redirect to take place once the ajax call has completed, in which case you should use:

    function submit(msg, evt) {
    
         if(msg == true) {
             $.ajax({
                 type:"POST",
                 data:{answer:'Correct'},
                 url:'https://myurl/p',
                 complete: function(){window.location="url";}
              });
         }
         evt.preventDefault();
         return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used href link in the flexigrid rows. on Click it takes me
I want to identify anchor tags that have an href containing a particular string
I have a WebBrowser control and try to set onclick and href attributes on
I have an website with URL`s like example.com/index.php?p=home An this script $(document).ready(function() { var
I have the following error: <a href=http://facebook.com/share.php?.... class=class>Click me</a> <div class=modal hide id=jpmodal> <div
I have this atm: <a href=<%= Url.RouteUrl(UserDelete, new { userID = item.UserID }) %>
I have a script that is looking for a live click event, but I
So I have the following code: $(document).on('click', 'a[data-link]', function () { var $this =
I have an href in HTML that I dynamically produce from a server. I
I have a href link and I would like it to be clicked when

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.