FatherShark
08-16-2005, 08:57 AM
Hi there, my name is Justin, and I am an Australian Web Development student currently having some trouble with a Javascript assignment. Here is my problem:
I will attach both the question, and my current solution, and if you could help at all, please reply - thanks:
****if the user clicks on the link to the ‘age.html’ page after 6pm the age page should not be displayed but instead an alert message should be displayed saying “This page is not available until tomorrow due to scheduled server maintenance. You should be doing your homework instead of playing on the computer anyway.”
This is not working for me - the alert does not appear, and the link to age.html is followed regardless of the time of day. Here is my HTML/javascript:
<html>
<head>
<link rel="stylesheet" href="style.css"/>
<script type="text/javascript">
function agecheck()
{
var current= new Date();
var daynight=current.getHours();
if (daynight<=18)
returnfalse();
alert('This page is not available until tomorrow due to scheduled server maintenance. You should be doing your homework instead of playing on the computer anyway');
else
returntrue();
}
</script>
</head>
<body>
<h1>Justin Newbury</h1>
<h2>Welcome Page</h2>
<script type="text/javascript">
var current= new Date();
var daynight=current.getHours();
if (daynight<=18)
document.write("<img src='images/day.jpg'>");
else
document.write("<img src='images/night.jpg'>");
</script>
<br />
<br />
<a href="photo.html">The Photo Page</a>
<br />
<a href="bit.html">A Bit About Me</a>
<br />
<a href="age.html" onClick="agecheck();">The Age Page</a>
<br />
</body>
</html>
I will attach both the question, and my current solution, and if you could help at all, please reply - thanks:
****if the user clicks on the link to the ‘age.html’ page after 6pm the age page should not be displayed but instead an alert message should be displayed saying “This page is not available until tomorrow due to scheduled server maintenance. You should be doing your homework instead of playing on the computer anyway.”
This is not working for me - the alert does not appear, and the link to age.html is followed regardless of the time of day. Here is my HTML/javascript:
<html>
<head>
<link rel="stylesheet" href="style.css"/>
<script type="text/javascript">
function agecheck()
{
var current= new Date();
var daynight=current.getHours();
if (daynight<=18)
returnfalse();
alert('This page is not available until tomorrow due to scheduled server maintenance. You should be doing your homework instead of playing on the computer anyway');
else
returntrue();
}
</script>
</head>
<body>
<h1>Justin Newbury</h1>
<h2>Welcome Page</h2>
<script type="text/javascript">
var current= new Date();
var daynight=current.getHours();
if (daynight<=18)
document.write("<img src='images/day.jpg'>");
else
document.write("<img src='images/night.jpg'>");
</script>
<br />
<br />
<a href="photo.html">The Photo Page</a>
<br />
<a href="bit.html">A Bit About Me</a>
<br />
<a href="age.html" onClick="agecheck();">The Age Page</a>
<br />
</body>
</html>