views:

157

answers:

3

instead of example:

$(".myfield").blur(function() {
    // validate
})
$(".myfield").keyup(function() {
    // validate
})

is there a way to combine these two?

+10  A: 

Yes

$(".myfield").bind('blur keyup', function(){
  // validate
});

Reference: .bind()

jAndy
Sweet! cheers Andy.
FFish
@FFish: here you go :)
jAndy
+3  A: 

In case you want to validate each for itself...

$('.myfield').live('blur keyup', function(event) {
  if (event.type == 'blur') {
    // validate on blur
  }
  if (event.type == 'keyup') {
    // validate on keyup
  }
});
gearsdigital
+1  A: 

As a side note, you might want to take a look att the jQuery Validate Plugin.

Tomas Lycken