O'Reilly logo

MooTools 1.3 Cookbook by Jay Larry G. Johnston

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Extending elements—prompt for confirmation on submit

Launching off the last extension, the forms on our site may also need to ask for confirmation. It is not unthinkable that a slip of the carriage return could accidentally submit a form before a user is ready. It certainly happens to all of us occasionally and perhaps to some of us regularly.

How to do it...

Mutate the HTML DOM FORM elements to act upon the onSubmit event and prompt whether to continue with the submission.

Element.implement({
polite_forms: function() {
if (this.get('tag')=='form') {
this.addEvent('submit',function(e) {
if(!confirm('Okay to submit form?')) {
e.stop();
}
});
}
}
});

How it works...

The polite_forms() method is added to all HTML DOM elements, but the execution is restricted ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required