• Archives

  • Confirming actions in javascript

    By admin | December 3, 2007

    Sometimes if a user is navigating away from your site or some hyperlink is there which is going to click u can add a confirm box so that he can change his decision or you show him something more intresting

    Using Confirm:

    <html>
    <head>
    <script type=”text/javascript”>
    function confirmaction()
    {
    var action=confirm(“Choose action”);
    if (action==true)
    {
    document.write(“You have pressed ok”);
    }
    else
    {
    document.write(“You have pressed Cancel”);
    }
    }
    </script>
    </head>
    <body>
    <input type=”button” onclick=”confirmaction()” value=”Button” />
    </body>
    </html>

    Example explained

    Now when you will click on the button

    the confirm command works and it will display

    a command prompt with a OK and CANCEL button if you pressed ok

    The action becomes true and the statement

    You have pressed ok

    will be displayed

    and the vice – versa (Reverse) If you pressed cancel

    Thanks

    krates

    Topics: Javascript | Comments Off on Confirming actions in javascript

    Related Links: