Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Confirmation Box onClick

    I have added a simple link to a page. Since this link causes an item to be deleted from the database, I would like a simple warning box to pop up with the option to cancel or confirm the deletion.

    I need some kind of onClick function for my <A> that opens a warning box and when OK is clicked the url is opened and if the Cancel button is clicked, nothing happens.

    I am sure that this must be relatively simple, it's just that I have never done this kind of thing before.

    Thanks
    eTheory - the theory of revolution

  • #2
    New Coder
    Join Date
    Jun 2002
    Location
    London & Oxford
    Posts
    97
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this:

    <script language="javascript" type="text/javascript">
    <!--
    function sure(){
    var sure = confirm("Are you sure?\r\n\r\nThis will permanantly delete from the database!");
    if(sure) location.replace('delete_page.asp');
    }
    //-->
    </script>

    and call it like this:

    <a href="javascript:void(0)" onclick="sure()">delete item?</a>

    Good luck
    As easy as 3.1415926535897932384626433832795028841

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, this code is good but is there another way of writing it so that I can still specify the url of the confirmation page. Within the <a tag> rather than within the java function.

    Because of the way the page is programmed, this would make things much easier.

    Thanks for your help.
    eTheory - the theory of revolution

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by Candrias77
    Thanks, this code is good but is there another way of writing it so that I can still specify the url of the confirmation page. Within the <a tag> rather than within the java function.

    Because of the way the page is programmed, this would make things much easier.

    Thanks for your help.
    Yes!
    Code:
    <a href="delete_page.asp" onclick="return confirm( 'Are you sure?\r\n\r\nThis will permanantly delete from the database!' );">delete item?</a>
    Or, done as a function
    Code:
    function confirmDelete()
    {
        return confirm( 'Are you sure?\r\n\r\nThis will permanantly delete from the database!' );
    }
    
    <a href="delete_page.asp" onclick="return confirmDelete();">delete item?</a>
    Last edited by beetle; 01-16-2003 at 08:43 PM.
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Perfect, thank you very much.
    eTheory - the theory of revolution


  •  

    Posting Permissions

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