Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6644025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:07:09+00:00 2026-05-26T00:07:09+00:00

I cannot seem to get this to work. I have a small JS file

  • 0

I cannot seem to get this to work. I have a small JS file that switches banners depending on the time of day, but it seems that doing an external reference in my PHP file does not work. It works fine in an HTML page.

This is the code in the JavaScript file.

function getStylesheet() {
    var currentTime = new Date().getHours();
    if (7 <= currentTime && currentTime < 19) {
        document.write("<img src='images/banner_day.jpg'>");
    } else {
        document.write("<img src='images/banner_night.jpg'>");
    }
}

getStylesheet();

And here is the reference code I used to call the JavaScript file. Its in a PHP file.

<script src="http://beta.website.com/wp-content/themes/theme/scripts/banner.js"></script>

Everything on the PHP page shows up in the browser, except for the banner that I tried to call with the script.


Here is the entire PHP file code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<div id="main">
<div class="container">
<div id="header">
<div id="logo">
<a href="http://bifffffdggdch.com"><img src="http://beta.dfdfdf.com/wp-content/themes/asdafd/images/logo.png" /></a>
</div>
<div id="shadow2"></div>
<div id="shadow1"></div>
<ul id="menu">
<li><a href="">df</a></li>
<li><a href="">df</a></li>
<li><a href="">fd df df</a></li>
<li><a href="">The asfdssd asdfds</a></li>
<li><a href="">sf</a></li>
<li><a href="">df</a></li>
<li><a href="">dfd</a></li>
</ul>
<div id="slogan"><big>"fasfdsads2005."</big></div>
<div id="loginDiv">Login Panel Here</div>
</div>
<div id="banner">
<script src="http://beta.adsfasfasfd.com/wp-content/themes/adfadsf/scripts/banner.js"></script></div>
<div class="sidebar">
Sidebar Content<br />
<br /><br /> 

blah
blah
blah
</div>

<div class="content">
Main Content

<br />
<br />
<br />

<br />
<br />
<br />

</div>

<div id="footer">
<div class="container">
        <div class="footer_column long">
          <h3>Cadsfadsfafdfsd.com All Rights Reserved</h3>
          <p>dsafasdfdffadffadsdafsdfsadafsdfsadfas</p>
        </div>
        <div class="footer_column2">
              <h3>More Links</h3>   
              <ul>
              <li><a href="http://aadfsdfsdfa.
              com">asfsdfa</a></li>
              <li><a href="http://ItsNotch.
              com">ItsNotch</a></li>
              <li><a href="http://adfasfsfaf.
              com">adsfasf</a></li>
              <li><a href="http://twitter.
              com/safs">Twitter</a></li>
              <li><a href="https://www.facebook.com/group.php?gid=10215yy20340498">Facebook Fan Page
              </a></li>
              </ul>
        </div>
        <div class="footer_column2">
              <h3>RSS</h3>
              <ul>
              <li><a href="">RSS Feed</a></li>
              <li><a href="">What is RSS?</a></li>
              </ul>
        </div>

    </div>
  </div>
</div>
</div>
</div>
</div>

</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:07:10+00:00Added an answer on May 26, 2026 at 12:07 am

    Try changing your Javascript to this:

    window.onload = function () {
    
      // Uncomment this line to make sure the script is loading/running, then delete it
      // alert('Hello, your Javascript is running');
    
      // Declare variables
      var currentTime, bannerDiv, newImg;
      // Get currentTime
      currentTime = new Date().getHours();
      // Get 'banner' div
      bannerDiv = document.getElementById('banner');
      // Get create a new <img>
      newImg = document.createElement('img');
      // Assign a src="" attribute depending on the time
      newImg.src = (currentTime > 7 && currentTime < 19) ? 'images/banner_day.jpg' : 'images/banner_night.jpg';
      // add the new image to the document
      bannerDiv.appendChild(newImg);
    
    };
    

    And put it in the <head> of the document, so change

    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      </head>
      <body>
        <!-- ....... -->
        <div id="banner">
          <script src="http://beta.adsfasfasfd.com/wp-content/themes/adfadsf/scripts/banner.js"></script>
        </div>
        <!-- ....... -->
    

    …to:

    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <script type="text/javascript" src="http://beta.adsfasfasfd.com/wp-content/themes/adfadsf/scripts/banner.js"></script>
      </head>
      <body>
        <!-- ....... -->
        <div id="banner"></div>
        <!-- ....... -->
    

    If it still doesn’t work, one of two things is happening:

    • Your javascript file is not actually at http://beta.adsfasfasfd.com/wp-content/themes/adfadsf/scripts/banner.js so the script cannot be loaded/run. Uncomment the first line to confirm that the script is running.
    • Your banner images cannot be found at images/banner_night.jpg – make sure your relative paths are correct.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot seem to get this to work, I have heard rumours that you
I have this design which I cannot seem to get right, I would like
This is a very old problem, but I cannot seem to get my head
I need a function, but cannot seem to get it quite right, I have
I have a this URL and I cannot seem to get the code below
I am trying this and cannot seem to get it to work. Can someone
This problem seems very simple, however I cannot get this to work. I have
So obviously I am doing something wrong, but I just cannot seem to get
I've been trying to get this to work. It's basically a way to have
I know I must be missing something here, but I cannot seem to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.