writing/calling a function
I've written the following function the check whether or not a required field is empty upon form submission:
Code:
$.fn.checkRequired = function(){
return this.each(function(){
if (this.val()==''){
$("<div class='error'>some error message</div>").insertAfter('this');
};
});
};
I then check on submission like this:
Code:
$('form').submit(function(){
return $('form.required').checkRequired();
});
I'm not sure if I'm not calling the function correctly or if the function has problems (or both). Any ideas on how I might do this?