Reputation: 27407
Currently I'm doing something like this in markup
<input type="text" ONKEYPRESS="InputNumeric(event);" id="txtNumber" />
But I want to use the jQuery bind method instead for all the obvious reasons.
jQuery(function($)
{
$("#txtNumber").bind("keyup", InputNumeric(event));
});
But when I try the above I get the below error
"event is not defined"
What should this syntax look like?
EDIT
The actual solution I got working is shown below.
$("#txtPriority").keypress(function (e) { InputInteger(e); });
Upvotes: 0
Views: 8971
Reputation: 193
looks like InputNumeric is an existing function that takes an event as parameter, In that case this should also work
$("#txtNumber").bind("keyup",InputNumeric);
Upvotes: 3
Reputation: 12217
Arguments passed back via jquery callbacks are always implied, so simply writing the function name is enough.
$("#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
Upvotes: 2
Reputation: 1841
jQuery(function($)
{
$("#txtNumber").bind("keyup", function(event) {InputNumeric(event);});
});
Upvotes: 4