...

View Full Version : Simple Javascript Question



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>

martin_narg
08-16-2005, 09:31 AM
Hopefully this could be of interest to you to modify and use in your script.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function checkAge() {
if((new Date).getHours() >= 18) {
alert("This page is not available until tomorrow due to scheduled server maintenance.\nYou should be doing your homework instead of playing on the computer anyway.");
return false;
}
return true;
}
</script>
</head>

<body>
<a href="age.html" onclick="return checkAge();">check age</a>
</body>
</html>


Hope this helps

m_n

FatherShark
08-17-2005, 12:34 AM
I'd like to thank you for your help.

Although I love HTML and CSS, coming from a non-programming background I am finding Javascript quite a challenge. Is there any on-line resources you might suggest to help bring me up to speed? I'd be satisfied if I can adapt existing code rather than just write it!

Mechlar
08-17-2005, 02:56 AM
I am in college for JavaScript also, and I am worried about taking regular programing courses like Pearl and C++. JavaScript is taking me awhile to get the hang of too.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum