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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:46:57+00:00 2026-05-11T19:46:57+00:00

I am try to use JQuery UI Dialog to replace the ugly javascript:alert() box.

  • 0

I am try to use JQuery UI Dialog to replace the ugly javascript:alert() box.
In my scenario, I have a list of items, and next to each individual of them, I would have a “delete” button for each of them.
the psuedo html setup will be something follows:

<ul>
    <li>ITEM <a href="url/to/remove"> <span>$itemId</span>
    <li>ITEM <a href="url/to/remove"><span>$itemId</span>
    <li>ITEM <a href="url/to/remove"><span>$itemId</span>
</ul>

<div id="confirmDialog">Are you sure?</div>

In JQ part, on document ready, I would first setup the div to be a modal dialog with necessary button, and set those “a” to be firing to confirmation before to remove, like:

$("ul li a").click(function() {
  // Show the dialog    
  return false; // to prevent the browser actually following the links!
}

OK, here’s the problem. during the init time, the dialog will have no idea who (item) will fire it up, and also the item id (!). How can I setup the behavior of those confirmation buttons in order to, if the user still choose YES, it will follow the link to remove it?

  • 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-11T19:46:58+00:00Added an answer on May 11, 2026 at 7:46 pm

    I just had to solve the same problem. The key to getting this to work was that the dialog must be partially initialized in the click event handler for the link you want to use the confirmation functionality with (if you want to use this for more than one link). This is because the target URL for the link must be injected into the event handler for the confirmation button click. I used a CSS class to indicate which links should have the confirmation behavior.

    Here’s my solution, abstracted away to be suitable for an example.

    <div id="dialog" title="Confirmation Required">
      Are you sure about this?
    </div>
    
    <script type="text/javascript">
      $(document).ready(function() {
        $("#dialog").dialog({
          autoOpen: false,
          modal: true
        });
      });
    
      $(".confirmLink").click(function(e) {
        e.preventDefault();
        var targetUrl = $(this).attr("href");
    
        $("#dialog").dialog({
          buttons : {
            "Confirm" : function() {
              window.location.href = targetUrl;
            },
            "Cancel" : function() {
              $(this).dialog("close");
            }
          }
        });
    
        $("#dialog").dialog("open");
      });
    </script>
    
    <a class="confirmLink" href="http://someLinkWhichRequiresConfirmation.com">Click here</a>
    <a class="confirmLink" href="http://anotherSensitiveLink">Or, you could click here</a>
    

    I believe that this would work for you, if you can generate your links with the CSS class (confirmLink, in my example).

    Here is a jsfiddle with the code in it.

    In the interest of full disclosure, I’ll note that I spent a few minutes on this particular problem and I provided a similar answer to this question, which was also without an accepted answer at the time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The vjslib.dll file is a redistributable file. You should be… May 11, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer Well, there's always Phalanger for running PHP within the .NET… May 11, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer The xterm which Apple ship with OS X appears to… May 11, 2026 at 11:52 pm

Related Questions

I just for the first time downloaded jquery and jquery-ui to use/learn last night.
So I did some reading of the related questions and had some interesting stuff
I am new in Jquery. I want to use sortableUI to my datalist. Each
I took a snapshot of the jquery.js file and jquery-ui files that I use

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.