Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2005
    Location
    Canberra, ACT
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple Javascript Question

    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>

  • #2
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Hopefully this could be of interest to you to modify and use in your script.

    Code:
    <!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
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #3
    New Coder
    Join Date
    Aug 2005
    Location
    Canberra, ACT
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #4
    New Coder
    Join Date
    Jul 2005
    Location
    Alabama
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Mandriva Club = $12.00/month
    Internet connection = $29.00/month
    A decent laptop = $1200.00
    Switching to Linux = Priceless

    Linux Member # ?????


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •