P
P
pvgdrk2014-12-09 23:47:19
JavaScript
pvgdrk, 2014-12-09 23:47:19

How to solve ReferenceError: event is not defined in Firefox when using jquery.validate?

Forms are created dynamically. Handlers are assigned to them by the desFormAction($from) function. jquery.validate is used to validate input.
In chrome everything works without problems. Firefox throws an error ReferenceError: event is not defined.

function desFormAction($myfrom){
    $myform.validate({
        rules: validationRm['rules'],
        messages: validationRm['messages'],
        submitHandler: function() {
            event.preventDefault();
            //...
            $.ajax({
                //...
            })
        }
    });
}

I found this solution:
stackoverflow.com/questions/4585970/jquery-event-p...
I tried to do this by analogy:
function desFormAction($myfrom){
    $myfrom.children('input[type=submit]').click(function(event){
        event.preventDefault();
        $myfrom.validate({
            rules: validationRm['rules'],
            messages: validationRm['messages'],
            submitHandler: function() {
                //...
                $.ajax({
                    //...
                })
            }
        });
    })
}

That doesn't work at all. (events go to validate, and there you can figure out what the hell is happening)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pvgdrk, 2014-12-14
@pvgdrk

The problem was solved unexpectedly for me. When using jquery.validate, you don't need to explicitly specify event.preventDefault(). The plugin has already done this for you.

M
Mikhail Osher, 2014-12-10
@miraage

function desFormAction($myfrom){
    $myfrom.submit(function(event){
        event.preventDefault();
        $myfrom.validate({
            rules: validationRm['rules'],
            messages: validationRm['messages'],
            submitHandler: function() {
                //...
                $.ajax({
                    //...
                })
            }
        });
    })
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question