I am using JavaScript to validate form fields. If it passes I want to send an event to Google analytics. However it isn't sending the event to GA. In my form I have:
<form role="form" name="submit" method="post" onSubmit="return validateForm();">
And my validation code is:
function validateForm() {
// validate the form and update the section if there is an error
var spamCheck = document.submit.inputSpamCheck.value;
if( document.submit.inputName.value == '' ){
document.submit.inputName.focus();
$( "#name-section" ).addClass( "has-error" );
return false;
}
else if( document.submit.inputEmail.value == '' ){
document.submit.inputEmail.focus();
$( "#email-section" ).addClass( "has-error" );
return false;
}
else if( document.submit.inputSpam.value != spamCheck ){
document.submit.inputSpam.focus();
$( "#spam-section" ).addClass( "has-error" );
return false;
}
else{
_gaq.push(['_trackEvent', 'Form', 'Submitted', 'successful', 5]);
return true;
}
}