SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    3 Post(s)
    0 Thread(s)

    Problem with confirmation button

    I've a problem with easy confirmation script. It goes to delete.php either you hit the ok or cancel buttons.

    <script type='text/javascript'>
    	function confirmDelete() {
    		return confirm("Are you sure you want to remove the user from database?");
    	echo "<a href='delete.php?user_id=" .$row['user_id']. "'><img src='images/delete.png' onclick='confirmDelete()' title='delete user' /></a>";
    Thanks for your help in advance

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Christchurch, New Zealand
    104 Post(s)
    4 Thread(s)
    The returned value from the confirmDelete function needs to be returned to the onclick event.

    When you use an inline attribute to assign a scripting event,

    Code html4strict:
    <... onclick='confirmDelete()'>

    This is the function that gets assigned to that event:

    Code javascript:
    function () {

    There are better ways to deal with that. For example, if you used scripting to assign confirmDelete to the event of the element, there is no outer function wrapper that needs to be dealt with, so the return from confirmDelete achieve exactly what needs to be achieved:

    Code javascript:
    var deleteUser = document.getElementById('delete');
    deleteUser.onclick = confirmDelete;

    But a few other preparation pieces need to be performed before you can start doing things so easily.

    So, in order for you to have the easiest solution (which may not be the best) you can just return to the event attribute the result of the confirmDelete function that you are calling.

    Code html4strict:
    <... onclick="return confirmDelete()">
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Posting Permissions

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