The confirmbox does not cancel the link behavior

L

lsolesen

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);
 
R

Richard Cornford

... . 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 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.
 
R

Richard Cornford

Lars said:
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.
 
P

petermichaux

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top