SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with javascript confirm

    Well, here is my confirm.

    Code JavaScript:
    function confirmDelete(msg)
    {
    var agree = confirm(msg);
    if (agree)
    	return true ;
    else
    	return false ;
    }

    Then, in the page, I am calling in this way:

    Code HTML4Strict:
    <a href="#" onclick="confirmDelete(<?=MSG?>); deleteFunction(<?=$id?>);"><?=CONFIRM?></a>

    Problem, irrespective of what I am clicking there in the confirm box, it is always executing the later function. Idea was that it will execute the later function only if confirm returns true ...

    Any help?
    Thanks.

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to check the result of the confirmDelete function.

    Something like:

    if (confirmDelete(<?=MSG?>)) deleteFunction(<?=$id?>);
    Teun Hoogendoorn
    ATSC
    LinkedIn
    Blog

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    <a href="#" onclick="if (confirm(<?=MSG?>) deleteFunction(<?=$id?>); return false;"><?=CONFIRM?></a>
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, this is working. Perfect. Thanks guys.


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
  •