SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,338
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Javascript Confirm Dialog button is not firing.

    I used this button to clear the database. It works perfectly:
    HTML Code:
    <input class="clearButton" type="button" value="Erase Data Now" onclick="clearData()">
    However, it would be better to put it in a confirm dialog to prevent accidental use. So I used this line to open a dialog box:
    HTML Code:
    <input class="clearButton" type="button" value="Clear Data" onclick="confirmation()">
    I used this script for the dialog box:

    Code:
       <script type="text/javascript">
                            // Confirm Dialog box from http://www.tizag.com/javascriptT/javascriptconfirm.php
                            function confirmation() {
                                var answer = confirm("Are you sure you want to erase ALL data you entered into the fields on this page? Action cannot be undone.")
                                if (answer){
                                    onclick="clearData()";
                                }
                                else{
                                    onclick="close()";
                                }
                            }
                           
                            </script>
    However, the
    Code:
    onclick="clearData()";
    is not firing, but the
    Code:
    onclick="close()";
    works fine, dismissing the dialog box.

    How do I incorporate the clearData so it works?

    Thanks!

  2. #2
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,338
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Just remove onclick=" and "; so the two lines in the dialog look like this:

    clearData()
    close()

    and it works!


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
  •