D
donpro
Hi,
I have a form with date fields, I have created event listeners to
check for a validate when leaving the field (onblur). If invalid, I
need it to set the field back to the default value, select the field,
and return focus to the field. All is working except the focus. If
someone can point out the error in my code, it would be appreciated.
function validateDateEntered(e) {
var elementValue = getSrcElement(e);
if(!dateCheck(elementValue.value,'%MM/%DD/%YYYY') && !
isWhitespace(elementValue.value)) {
alert('Invalid Received date - format is MM/DD/YYYY and must be a
valid date');
elementValue.value=elementValue.defaultValue;
elementValue.select();
elementValue.focus();
if (e.preventDefault) {
e.preventDefault();
}
e.returnValue = false;
}
}
function getSrcElement(e) {
elementClicked = 0;
if (window.event && window.event.srcElement) {
elementClicked = window.event.srcElement;
}
if (e && e.target) {
elementClicked = e.target;
}
return elementClicked;
}
I have a form with date fields, I have created event listeners to
check for a validate when leaving the field (onblur). If invalid, I
need it to set the field back to the default value, select the field,
and return focus to the field. All is working except the focus. If
someone can point out the error in my code, it would be appreciated.
function validateDateEntered(e) {
var elementValue = getSrcElement(e);
if(!dateCheck(elementValue.value,'%MM/%DD/%YYYY') && !
isWhitespace(elementValue.value)) {
alert('Invalid Received date - format is MM/DD/YYYY and must be a
valid date');
elementValue.value=elementValue.defaultValue;
elementValue.select();
elementValue.focus();
if (e.preventDefault) {
e.preventDefault();
}
e.returnValue = false;
}
}
function getSrcElement(e) {
elementClicked = 0;
if (window.event && window.event.srcElement) {
elementClicked = window.event.srcElement;
}
if (e && e.target) {
elementClicked = e.target;
}
return elementClicked;
}