Code:
<script>
function checkBirthday() {
if( !/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.test(obj.value) ) {
alert( "Invalid date supplied - must be format DD/MM/YYYY" );
return false;
}
var d = new Date();
var d2 = new Date(RegExp.$3, RegExp.$2, RegExp.$1);
var diff = d.getDiff(d2, "y")
if( isNaN(diff) ) {
alert( "Invalid date supplied" );
return false;
} else if( diff < 2 ) {
return true;
} else if( diff > 2 ) {
alert( "This is NOT an INFANT \n they are older than 2" );
document.form.birthday.value = "";
document.form.date.focus();
return false;
}
}
</script>
You should really get into the habit of better naming conventions for your HTML elements, for example "frmBirthday" would be better than "form" and "txtDate" better than "date". This is for clarification in the code between JavaScript objects and HTML element ID's (ie clarification between the JavaScript Date object and date being the name of the form - only a capital D seperates the two.
We would need to see the checkRetdt() function to see what it does, but this is essentially the code if checkRetdt() returns true/false
Code:
<a href="#" onclick="if(checkBirthday()&&checkRetdt(document.form.retdt))document.form.submit();return false;"></a><img src="g_toolbar_flights.gif" border="0"></a>
(I'm sure i've written your original code in a previous post before it's been modified)
Hope this helps
m_n