Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2013
    Thanked 0 Times in 0 Posts

    Dynamic Background Image Depending on Time of Day

    Hi Guys,

    Relatively new to javascript, I have a few books and I've been going on W3Schools for a few weeks now. I wrote the following and am unable to get the background to change, any ideas?

    // Dynamic Background for HTML5 template based on time of day.
    function dynamicBG(){
    	var d  = new Date();
    	var h = d.getHours();
    	if ((h <= 5) && (h >=18))
    		document.getElementById("bgText").innerHTML="The BG Should be Day Time";
    		} else{
    		document.getElementById("bgText").innerHTML="The BG Should be Night Time";
    	window.onload = dynamicBG();
    The second output for the innerHTML is just to validate what is posted back to the page on load, but nothing happens.

    Blank screen and just a heading.

    Anyone shed any light on it?!

  2. #2
    Senior Coder
    Join Date
    Sep 2010
    Thanked 275 Times in 275 Posts
    && equals AND. It can't be both <= 5 and >= 18 at the same time. Maybe you mean

    || which equals OR.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.

    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.


Posting Permissions

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