tags:

views:

1482

answers:

3

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); });
+4  A: 
jQuery(function($)
{
    $("#txtNumber").bind("keyup", function(event) {InputNumeric(event);});
});
matthewk
Actually it should be:$(document).ready(function () {$("#txtNumber").bind("keyup", function(event) {InputNumeric(event);});});
matthewk
$(function () { is shorthand for $(document).ready()jQuery(function($) { is the same thing in noConflict mode.
Bruce Aldridge
+3  A: 

looks like InputNumeric is an existing function that takes an event as parameter, In that case this should also work

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

kamal.gs
+1  A: 

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

sanchothefat