I have some simple form validation going on, and it works in FF and IE. Simply put, if there is a date out of range on the form, javascript prevents the form submission. However, in Chrome, it's totally broken. When the preventDefault fires, Chrome logs the user out of the application and they get kicked back to the index/login page. And I have no clue why.
The code I am using is here:
function cancelEvent (e) {
if (e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = false;
}
}
It's fed by
function validateFields(evt) {
evt = evt ? evt : window.event;
var invalid = false;
//validation #1: Consent Date should NOT be in the future
var today = new Date();
var consentDate = document.forms["ptform"].elements["calConsent"].value;
var consDate=convertDate(consentDate);
if(consDate>today){
invalid=true;
var consentDateTitle=document.getElementById("consentDateTitle");
consentDateTitle.className = consentDateTitle.className + " errormessage";
alert("Consent Date cannot be in the future");
}
//end validation #1
if (invalid) {
cancelEvent(evt);
}
}
And that's pretty much it. Works fine in FF and IE but Chrome freaks out. Any ideas why? I'm not a js expert... :(
my event handler code:
// listen to an event
function listenEvent(eventObj, event, eventHandler) {
if (eventObj.addEventListener) {
eventObj.addEventListener(event, eventHandler,false);
} else if (eventObj.attachEvent) {
event = "on" + event;
eventObj.attachEvent(event, eventHandler);
} else {
eventObj["on" + event] = eventHandler;
}
}