I tried binding a named function to a form submit event. At first, I tried binding it to an anonymous function and it worked:
jQuery("#form").submit(function(event){
event.preventDefault();
alert("event");
var reqType = jQuery(this).find('input[name="requestType"]').val();
alert("requestType:"+reqType);
});
And it worked fine. But when I used a named function:
//inside jQuery(document).ready()
jQuery("#form").submit(processForm(event));
//defined outside jQuery(document).ready()
function processForm(event) {
event.preventDefault();
var reqType = jQuery(this).find('input[name="requestType"]').val();
alert("request type: "+reqType);
}
Not only does the function did not work as I hoped it would, the alert() would just fire when the page is refresh while the form is not submitted. What could be the cause of this and how do I fix it? Thanks in advance.