SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Online Dating Guru rawnet's Avatar
    Join Date
    Jan 2002
    Location
    Windsor, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation How do I do a Confirm Dialog box with <a> ?

    Hello,

    I've searched these forums but have been unable to find a solution to this - probably because it's too simple for most people here, but an HTML muppet like myself is a bit stuck!!

    Basically, I'd like the code for a simple Confirm Dialog box.

    My message is dynamic - I just want a confirmation box to appear when people click on a link which leads to a delete script.

    I was wondering if people had both the <script> part and the <a> part to initialise the dialog box?

    My apologies for posting something so basic - hope somebody can help,

    All the best,

    Kind Regards,

    Ross Williams

  2. #2
    SitePoint Evangelist pip's Avatar
    Join Date
    Jun 2001
    Location
    Cape Town, South Africa
    Posts
    548
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Ross,

    Try using the following

    <SCRIPT LANGUAGE="JavaScript">
    function confirmBox(msg) {
    if(confirm(msg)){
    alert("File Deleted");
    } else {
    alert("Operation Canceled");
    }
    }
    </SCRIPT>

    <A HREF="JavaScript:confirmBox('Are you sure that you want to delete this file?')">Click</A>
    - Pip
    ---------------------------------------------------------------------------------
    Nothing takes the taste out of peanut butter quite like unrequited love.

  3. #3
    SitePoint Evangelist pip's Avatar
    Join Date
    Jun 2001
    Location
    Cape Town, South Africa
    Posts
    548
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh yea... and if you want the page to redirect when the user clicks "OK", replace the first alert method

    alert("File deleted")

    with

    top.location='**Script to redirect to**';
    - Pip
    ---------------------------------------------------------------------------------
    Nothing takes the taste out of peanut butter quite like unrequited love.

  4. #4
    Online Dating Guru rawnet's Avatar
    Join Date
    Jan 2002
    Location
    Windsor, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Pip,

    Cheers for that - looks good. Is there any way to pass the URL (where I want the user to go when they click "Okay") in the <A href.. part? The URL will vary as there'll be around 50 links on the page with a unique URL, all of which need a confirmation script like this.

    Any ideas?

    Ross

  5. #5
    SitePoint Evangelist pip's Avatar
    Join Date
    Jun 2001
    Location
    Cape Town, South Africa
    Posts
    548
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Erm....

    What you could do is cancel the default action depending on which button was clicked.

    Try using the following:

    <SCRIPT LANGUAGE="JavaScript">
    function cancelDefaultEvent() {
    event.cancelBubble = true;
    event.returnValue = false;
    return false;
    }

    function confirmBox(msg) {
    if(confirm(msg)) {

    } else {
    cancelDefaultEvent();
    }
    }
    </SCRIPT>


    <A HREF="http://www.pip.co.za/" onClick="confirmBox('Are you sure?')">Click me</A>

    I'm not sure if this answers your question, but check it out and let me know!
    - Pip
    ---------------------------------------------------------------------------------
    Nothing takes the taste out of peanut butter quite like unrequited love.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •