views:

24

answers:

1

jQuery Validation plugin has "element" argument for required rule. I know how to use it for inline functions but what if I want to pass it to out-of-line JS function? I tried this:

rules: { startHours: { required: startTimeRequired(element) },

but it didn't work.

+1  A: 

You just reference the function itself, element is passed for you:

rules: { startHours: { required: startTimeRequired },

startTimeRequired() (if the parens are there) tells javascript to run the function then, which isn't what you want. You want to tell the required event handler to throw 'event' at startTimeRequired.

Dan Heberden