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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:03:43+00:00 2026-06-03T05:03:43+00:00

I want this link to have a JavaScript dialog that asks the user Are

  • 0

I want this link to have a JavaScript dialog that asks the user “Are you sure? Y/N”.

<a href="delete.php?id=22">Link</a>

If the user clicks “Yes”, the link should load, if “No” nothing will happen.

I know how to do that in forms, using onclick running a function that returns true or false. But how do I do this with an <a> 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-03T05:03:45+00:00Added an answer on June 3, 2026 at 5:03 am

    Inline event handler

    In the most simple way, you can use the confirm() function in an inline onclick handler.

    <a href="delete.php?id=22" onclick="return confirm('Are you sure?')">Link</a>
    

    Advanced event handling

    But normally you would like to separate your HTML and Javascript, so I suggest you don’t use inline event handlers, but put a class on your link and add an event listener to it.

    <a href="delete.php?id=22" class="confirmation">Link</a>
    ...
    <script type="text/javascript">
        var elems = document.getElementsByClassName('confirmation');
        var confirmIt = function (e) {
            if (!confirm('Are you sure?')) e.preventDefault();
        };
        for (var i = 0, l = elems.length; i < l; i++) {
            elems[i].addEventListener('click', confirmIt, false);
        }
    </script>
    

    This example will only work in modern browsers (for older IEs you can use attachEvent(), returnValue and provide an implementation for getElementsByClassName() or use a library like jQuery that will help with cross-browser issues). You can read more about this advanced event handling method on MDN.

    jQuery

    I’d like to stay far away from being considered a jQuery fanboy, but DOM manipulation and event handling are two areas where it helps the most with browser differences. Just for fun, here is how this would look with jQuery:

    <a href="delete.php?id=22" class="confirmation">Link</a>
    ...
    <!-- Include jQuery - see http://jquery.com -->
    <script type="text/javascript">
        $('.confirmation').on('click', function () {
            return confirm('Are you sure?');
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want a link that does nothing. I don't want this: <a href=#> because
I have this link: <p id=accept-favor><a title=Accept this Favor href=?wp_accept_favor=<?php comment_ID(); ?>>Accept this Favor</a></p>
Say I have a URL: <a href=hello.html id=4298>hello</a> When someone clicks this link, I
I have this link <div class=new-div ><a href=<?php the_permalink(); ?>><?php the_title(); ?> In this
I want to create a link like this: <a href=http://example.com>text</a> and replace the behavior
i want something like this the user enter a website link i need check
I want to add this code: <link rel=stylesheet type=text/css href=css/global.css /> <!--[if lt IE
By using javascript confim i have done suspending. Now i want to turn this
I have a large excel document that is generated when the user clicks on
I have a simple link: <a href=# id=test>Test Link</a> I want to get an

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.