Comparing date with today's date (Java Script)
Hi all.
I am new to Java Script.
I try to make function to compare date with current date.
If the date entered by the user is greater than current date, it will display alert message.
However, it is not functioning.
Can anyone explain to me what is wrong with the function.
And, correct me if I am wrong.
Thanks in advance.
Below is the function.
HTML Code:
<script language="javascript1.2">
function tarikh_lantikan()
{
valf = "dd/MM/y";
var myDate = document.form1.tarikhmula.value;
var today = new Date();
myDate2 = isDate(myDate,valf);
today2 = isDate(today,valf);
if (myDate2 > today2)
{
alert('Tarikh salah.');
document.form1.tarikhmula.focus();
return false;
}
}
</script>
Re: Comparing date with today's date (Java Script)
I can only assume there is a problem with your isDate function.
Re: Comparing date with today's date (Java Script)
Is there an error message?
If you are unsure how to see JS error messages, in IE it is shown as a small icon on the status bar with the text "Error on page". In Firefox it is under Tools -> Javascript Console.
Also, don't use the "language" attribute of script tags. This is deprecated. Instead, use the "type" attribute.
HTML Code:
<script type="text/javascript">