Skip to Main Content
MooTools 1.3 Cookbook
book

MooTools 1.3 Cookbook

by Jay L Johnston
July 2011
Intermediate to advanced content levelIntermediate to advanced
276 pages
5h 11m
English
Packt Publishing
Content preview from MooTools 1.3 Cookbook

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Jump Start Web Performance

Jump Start Web Performance

Craig Buckler

Publisher Resources

ISBN: 9781849515689Other