franches
09-21-2004, 02:53 AM
hi,
i'm a newbie in javascript. could someone examine my code. The code checks if the user entered a date advance with the current date. The date today is september 21, 2004 if the user pressed october 21, 2004 then a message will display I'm sorry, Logging in advance is not allowed. When I test my code it always display Congratulations eventhough i tried september 21, 2005.
thanks. hope someone would help me.
<html>
<head>
</head>
<body>
<script language="javascript">
function checkdate()
{
var d = new Date() ;
var mydate=d.getDate() + (d.getMonth()+1) + d.getFullYear();
var myDayStr = document.CheckDate.formDate.value;
var myMonthStr = document.CheckDate.formMonth.value;
var myYearStr = document.CheckDate.formYear.value;
var myDateStr = myDayStr + myMonthStr + myYearStr;
if ( myDateStr > mydate ) {
alert( 'I\'m sorry, Logging in advance is not allowed' );
} else {
alert( 'Congratulations!' );
}
}
</script>
<FORM NAME=CheckDate METHOD=POST >
<SELECT NAME=formMonth id=formMonth onchange="checkdate()">
<OPTION VALUE=Jan>Jan
<OPTION VALUE=Feb>Feb
<OPTION VALUE=Mar>Mar
<OPTION VALUE=Apr>Apr
<OPTION VALUE=May>May
<OPTION VALUE=Jun>Jun
<OPTION VALUE=Jul>Jul
<OPTION VALUE=Aug>Aug
<OPTION VALUE=Sep>Sep
<OPTION VALUE=Oct>Oct
<OPTION VALUE=Nov>Nov
<OPTION VALUE=Dec>Dec
</SELECT>
<SELECT NAME=formDate id=formDate onchange="checkdate()">
<OPTION VALUE=1>1
<OPTION VALUE=2>2
<OPTION VALUE=3>3
<OPTION VALUE=4>4
<OPTION VALUE=5>5
<OPTION VALUE=6>6
<OPTION VALUE=7>7
<OPTION VALUE=8>8
<OPTION VALUE=9>9
<OPTION VALUE=10>10
<OPTION VALUE=11>11
<OPTION VALUE=12>12
<OPTION VALUE=13>13
<OPTION VALUE=14>14
<OPTION VALUE=15>15
<OPTION VALUE=16>16
<OPTION VALUE=17>17
<OPTION VALUE=18>18
<OPTION VALUE=19>19
<OPTION VALUE=20>20
<OPTION VALUE=21>21
<OPTION VALUE=22>22
<OPTION VALUE=23>23
<OPTION VALUE=24>24
<OPTION VALUE=25>25
<OPTION VALUE=26>26
<OPTION VALUE=27>27
<OPTION VALUE=28>28
<OPTION VALUE=29>29
<OPTION VALUE=30>30
<OPTION VALUE=31>31
</SELECT>
<SELECT NAME=formYear id=formYear onchange="checkdate()">
<OPTION VALUE=1980>2004
<OPTION VALUE=1980>2005
<OPTION VALUE=1980>2006
</SELECT>
<FORM>
</body>
</html>
i'm a newbie in javascript. could someone examine my code. The code checks if the user entered a date advance with the current date. The date today is september 21, 2004 if the user pressed october 21, 2004 then a message will display I'm sorry, Logging in advance is not allowed. When I test my code it always display Congratulations eventhough i tried september 21, 2005.
thanks. hope someone would help me.
<html>
<head>
</head>
<body>
<script language="javascript">
function checkdate()
{
var d = new Date() ;
var mydate=d.getDate() + (d.getMonth()+1) + d.getFullYear();
var myDayStr = document.CheckDate.formDate.value;
var myMonthStr = document.CheckDate.formMonth.value;
var myYearStr = document.CheckDate.formYear.value;
var myDateStr = myDayStr + myMonthStr + myYearStr;
if ( myDateStr > mydate ) {
alert( 'I\'m sorry, Logging in advance is not allowed' );
} else {
alert( 'Congratulations!' );
}
}
</script>
<FORM NAME=CheckDate METHOD=POST >
<SELECT NAME=formMonth id=formMonth onchange="checkdate()">
<OPTION VALUE=Jan>Jan
<OPTION VALUE=Feb>Feb
<OPTION VALUE=Mar>Mar
<OPTION VALUE=Apr>Apr
<OPTION VALUE=May>May
<OPTION VALUE=Jun>Jun
<OPTION VALUE=Jul>Jul
<OPTION VALUE=Aug>Aug
<OPTION VALUE=Sep>Sep
<OPTION VALUE=Oct>Oct
<OPTION VALUE=Nov>Nov
<OPTION VALUE=Dec>Dec
</SELECT>
<SELECT NAME=formDate id=formDate onchange="checkdate()">
<OPTION VALUE=1>1
<OPTION VALUE=2>2
<OPTION VALUE=3>3
<OPTION VALUE=4>4
<OPTION VALUE=5>5
<OPTION VALUE=6>6
<OPTION VALUE=7>7
<OPTION VALUE=8>8
<OPTION VALUE=9>9
<OPTION VALUE=10>10
<OPTION VALUE=11>11
<OPTION VALUE=12>12
<OPTION VALUE=13>13
<OPTION VALUE=14>14
<OPTION VALUE=15>15
<OPTION VALUE=16>16
<OPTION VALUE=17>17
<OPTION VALUE=18>18
<OPTION VALUE=19>19
<OPTION VALUE=20>20
<OPTION VALUE=21>21
<OPTION VALUE=22>22
<OPTION VALUE=23>23
<OPTION VALUE=24>24
<OPTION VALUE=25>25
<OPTION VALUE=26>26
<OPTION VALUE=27>27
<OPTION VALUE=28>28
<OPTION VALUE=29>29
<OPTION VALUE=30>30
<OPTION VALUE=31>31
</SELECT>
<SELECT NAME=formYear id=formYear onchange="checkdate()">
<OPTION VALUE=1980>2004
<OPTION VALUE=1980>2005
<OPTION VALUE=1980>2006
</SELECT>
<FORM>
</body>
</html>