• 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:

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

    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



    Topics: Javascript | Comments Off on Confirming actions in javascript

    Related Links: