Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 746565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:06:19+00:00 2026-05-14T14:06:19+00:00

Normally, if I wish to stop a default event in mootools I can do

  • 0

Normally, if I wish to stop a default event in mootools I can do this:

$('form').addEvent('submit', function(e) {
    e.stop();

    //Do stuff here
    });

However, I don’t like using an anonymous function in events because I often want to reuse the code. Lets say I have a validate function. I could do this:

$('form').addEvent('submit', validate);

which works fine until I want to stop the default event. validate obviously doesn’t know what e is so I can’t just do e.stop(). Also I’ve tried passing the event as a variable to validate but whenever I use a named function with parameters, the function gets called automatically on domready, rather than on the event firing. Even worse, an error is thrown when the event is fired.

What am I doing wrong?

UPDATE: Here is the validate function in full, just in case. However, since the error is occurring after the first line, I doubt anything after is being called so it is probably irrelevant.

var validate = function(e) {
    e.stop();

    if(this.get('tag') === 'form') {
        this.getElements('input.text').each(validate);
        }
    else {
        element = this;
        div = element.getParent();
        input = element.get('value');
        filter = JSON.decode(div.get('filter'));

        if(!filter.some(function(value, key) {
            if(value === 'required') if(!setAndNotEmpty(element, input)) return true;
            if(value === 'email') if(!isEmail(element, input)) return true;
            if(value === 'date') if(!isDate(element, input)) return true;
            if(value === 'time') if(!isTime(element, input)) return true;
            if(key === 'chars') if(!charsLessThan(element, input, value)) return true;
            if(key === 'words') if(!wordsLessThan(element, input, value)) return true;
            return false;
            })) setFault('', element);
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:06:20+00:00Added an answer on May 14, 2026 at 2:06 pm

    you need to declare “validate” as follows:

    function validate(e){
    }
    

    Then you can use e.stop()

    function validate(e){
        e.stop();
    }
    
    $('form').addEvent('submit', validate);
    

    of note is that in jQuery, you can also return a result from a method to stop propogation. I’m not sure if mootools allows this, but you could possibly do this by:

    function validate(e){
        return false;
    }
    
    $('form').addEvent('submit', validate);
    

    To answer the “what am I doing wrong” part – you’re simply misunderstanding what is happening when you pass in an anonymous method. Passing an anonymous method function(e) {} is not causing e to be passed, it is simply defining the name of the first argument to be passed in. The event object will be passed into the method whether or not the method names the argument, hence you will find that the following would also work:

    function validate(){
        arguments[0].stop();
    }
    
    $('form').addEvent('submit', validate);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Normally if you wish to change a variable with regex you do this: $string
Normally, you can change the default root drive to install your application to using:
Normally, when tabbing through controls on a form, when the focus is set to
Normally with Java Swing you can set the background color of a button with:
Normally I do this for all my user inputs both strings and numerical inputs:
I wish to make interactive code learning system, it allows users, (young programmers normally)
I would normally do this sort of thing in jQuery, but this will require
Normally you would have a single ErrorProvider for all the controls on a form;
Normally this would be something like: glutAddMenuEntry(-, <opid>); But it doesn't work. After looking
Normally you create a function using cfscript like: <cfscript> function foo() { return bar;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.