The confirmbox does not cancel the link behavior

Discussion in 'Javascript' started by lsolesen@gmail.com, May 28, 2006.

  1. Guest

    I used the following javascript to add confirm-boxes to links. The
    confirm-boxes are added at runtime for links with the class "delete".

    The script adds the function to the links. When I click the link, the
    confirm box i shown. But then it breaks; no matter if I press Cancel og
    Ok, there is the same behavior => the link is followed. I wonder why
    that is - off course I don't want to follow the link, if I select
    Cancel.

    var confirmboxes = {


    init: function() {
    confirmboxes.apply("delete");
    },


    apply: function(sClass) {
    var elements =
    YAHOO.util.Dom.getElementsByClassName(sClass, "a",
    "content");
    if (!elements) return;
    var n = elements.length;
    for (var i=0; i<n;i++) {
    YAHOO.util.Event.addListener(elements,
    "click", function() {
    return confirm("Er du sikker?");
    });
    }
    return false;
    },



    }


    YAHOO.util.Event.addListener(window, "load", confirmboxes.init);
    , May 28, 2006
    #1
    1. Advertising

  2. wrote:
    <snip>
    > ... . But then it breaks; no matter if I press Cancel
    > og Ok, there is the same behavior => the link is
    > followed. I wonder why that is - off course I don't want
    > to follow the link, if I select Cancel.

    <snip>
    > var n = elements.length;
    > for (var i=0; i<n;i++) {
    > YAHOO.util.Event.addListener(elements,
    > "click", function() {
    > return confirm("Er du sikker?");
    > });

    <snip>

    You have not posted the code for - YAHOO.util.Event.addListener - so its
    mechanism is unknown. However, it looks like it does not include a
    mechanism for cancelling the default action of event handlers by
    returning true/false from the event handling function. The best source
    of information on cancelling default actions with this code is its
    documentation.

    Richard.
    Richard Cornford, May 28, 2006
    #2
    1. Advertising

  3. Lars Guest

    Lars, May 28, 2006
    #3
  4. Lars wrote:
    >>You have not posted the code for - YAHOO.util.Event.addListener
    >> - so its mechanism is unknown.

    >
    > YAHOO.util.Event.addListener is documented here:

    <snip>

    Are you proposing that I read hundreds, or even thousand, of lines of
    code that I may never use myself just to answer a question here?

    Richard.
    Richard Cornford, May 29, 2006
    #4
  5. Guest

    wrote:
    > I used the following javascript


    snip
    > var elements =
    > YAHOO.util.Dom.getElementsByClassName(sClass, "a",
    > "content");



    snip
    > YAHOO.util.Event.addListener(elements,
    > "click", function() {


    snip
    >
    >
    > YAHOO.util.Event.addListener(window, "load", confirmboxes.init);


    You might have good luck asking this on the Yahoo! UI mailing list.

    http://developer.yahoo.com/yui/#support

    Peter
    , May 29, 2006
    #5
  6. Lars Guest

    > You might have good luck asking this on the Yahoo! UI mailing list.

    Thanks.

    --
    Lars Olesen
    Lars, Jun 2, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JerryK

    confirm does not cancel postback?

    JerryK, Mar 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    5,436
    JerryK
    Mar 22, 2005
  2. Kevin Spencer

    Re: Link Link Link DANGER WILL ROBINSON!!!

    Kevin Spencer, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    782
    Kevin Spencer
    May 17, 2005
  3. gnewsgroup
    Replies:
    0
    Views:
    469
    gnewsgroup
    Dec 27, 2007
  4. shapper

    ListView. Cancel. It does not!

    shapper, Mar 6, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    363
    shapper
    Mar 6, 2008
  5. Julia B
    Replies:
    2
    Views:
    319
    Julia B
    Apr 11, 2006
Loading...

Share This Page