JQuery bind error "event not defined"

I am currently doing something like this in markup

<input type="text" ONKEYPRESS="InputNumeric(event);" id="txtNumber" />

      

But I want to use jQuery's bind method instead of all the obvious reasons.

jQuery(function($)
{
    $("#txtNumber").bind("keyup", InputNumeric(event));
});

      

But when I try to do this I get the following error

"event not defined"

What does this syntax look like?

EDIT

The actual solution I got is shown below.

$("#txtPriority").keypress(function (e) { InputInteger(e); });

      

0


source to share


3 answers


jQuery(function($)
{
    $("#txtNumber").bind("keyup", function(event) {InputNumeric(event);});
});

      



+4


source


looks like InputNumeric is an existing function that takes an event as a parameter, in this case this should work too



$("#txtNumber").bind("keyup",InputNumeric);

+3


source


Arguments passed back through jquery callbacks are always implied, so just write the function name.

$("#txtNumber").bind("keyup",InputNumeric);

function InputNumeric(event){
    $(event.target).dosomething(); // is the same as
    $(this).dosomething();
}

      

Example: http://www.sanchothefat.com/dev/sfhelp/jquery-args.html

+2


source







All Articles