/    Sign up×
Community /Pin to ProfileBookmark

Rotating .js files by day of the week – wonky script

For some reason this script does not rotate my Java scripts by day of the week. Does anyone know why? I think it is something to do with “document.get” which is needed for objects I think.

<SCRIPT LANGUAGE=”JavaScript”>
today = new Date();
day = today.getDay();
arday = new Array(“sunday.js”, “monday.js”, “tuesday.js”,
“wednesday.js”, “thursday.js”, “friday.js”, “saturday.js”);
document.get(“<src=’http://www.mysite.com/index_files/” + arday[day] + “‘>”);
</script>

(By the way, the same script works fine with images like this…
<SCRIPT LANGUAGE=”JavaScript”>
today = new Date();
day = today.getDay();
arday = new Array(“sunday.jpg”, “monday.jpg”, “tuesday.jpg”,
“wednesday.jpg”, “thursday.jpg”, “friday.jpg”, “saturday.jpg”);
document.write(“<img src=’http://www.mysite.com/index_files/” + arday[day] + “‘>”);
</script>)

Cheers.

to post a comment
JavaScript

12 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyJul 25.2005 — nah just use document.write
[CODE]
document.write('<scr'+'ipt type="text/javascript" src="link/to/file.js">');
document.write('</script>');
[/CODE]
Copy linkTweet thisAlerts:
@Felix67authorJul 25.2005 — nah just use document.write
[CODE]
document.write('<scr'+'ipt type="text/javascript">');
document.write('<src = ....................');
document.write('</script>');
[/CODE]
[/QUOTE]


tried it before - "document.write" does not work with objects.

Cheers
Copy linkTweet thisAlerts:
@bathurst_guyJul 25.2005 — what is the goal, from the information provided what i responded with works...

P.S. i modified the code
Copy linkTweet thisAlerts:
@Felix67authorJul 25.2005 — the goal is to automatically rotate a .js file so a different one appears each day. So the monday.js file appears on Monday etc.

Rotating .jpg files by day of week, as I say, works fine so I'm at a loss why the script won't rotate for .js files too.

*scratching my head here*

Cheers
Copy linkTweet thisAlerts:
@bathurst_guyJul 25.2005 — Did you even try my code?
Copy linkTweet thisAlerts:
@Felix67authorJul 25.2005 — Did you even try my code?[/QUOTE]

thanks large for your patience here but, um, I'm drawing a blank. This does not work, which I hope combines your script as per your suggestion:

<script>

today = new Date();

day = today.getDay();

arday = new Array("sunday.js", "monday.js", "tuesday.js",

"wednesday.js", "thursday.js", "friday.js", "saturday.js");

document.write("<scr'+'ipt type="text/javascript">");

document.write("<src='http://www.mysite.com/index_files/" + arday[day] + "'>");

document.write("</script>");
Copy linkTweet thisAlerts:
@bathurst_guyJul 25.2005 — Sorry yeh i had edited the script, while i was editing it must of been when you replied the first time.
[CODE]
<script>
today = new Date();
day = today.getDay();
arday = new Array("sunday.js", "monday.js", "tuesday.js",
"wednesday.js", "thursday.js", "friday.js", "saturday.js");
document.write('<scr'+'ipt type="text/javascript" src="http://www.mysite.com/index_files/' + arday[day] +'">');
document.write("</script>");
</script>
[/CODE]
Copy linkTweet thisAlerts:
@Felix67authorJul 25.2005 — Thanks again

Still no joy but I tried your script in Frontpage and it seems to splutter at this last line...

document.write("</script>");

This bit here [ /script>"); ] always comes out in black rather than red, if you know what I mean re Frontpage.

(Also I presume you mean "src" rather than "scr"?) This is the latest code I have :

<script>

today = new Date();

day = today.getDay();

arday = new Array("sunday.js", "monday.js", "tuesday.js",

"wednesday.js", "thursday.js", "friday.js", "saturday.js");

document.write('<scr'+'ipt type="text/javascript" src="http://www.mysite.com/index_files/' + arday[day] +'">');

document.write("</script>");

</script>
Copy linkTweet thisAlerts:
@bathurst_guyJul 25.2005 — Well it works for me....?

It must be monday.js

And little note, there are much better programs to use than Frontpage, it saves a lot of useless code with the site. I use Dreamweaver but if you cant afford it I recommend something like EditPlus
Copy linkTweet thisAlerts:
@Felix67authorJul 25.2005 — noted on Frontpage. It's a very simple site so I'm just going with what I have free on the laptop. I shall definitely try to check out these products when it gets a bit better.

the monday.js files and all of them I can vouch for as they are all on another page of the site and functioning 100% no problem

Mmm, well I wonder is it cool to show me the site where it is working for you? Maybe seeing somebody else succesful with it will help me sort it out

Thanks again for your help :-)
Copy linkTweet thisAlerts:
@bathurst_guyJul 25.2005 — Okay I have this in a file named monday.js
[CODE]
document.write('Monday is today');
[/CODE]

and have this html page
[CODE]
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<script type="text/javascript">
today = new Date();
day = today.getDay();
arday = new Array("sunday.js", "monday.js", "tuesday.js",
"wednesday.js", "thursday.js", "friday.js", "saturday.js");
document.write('<scr'+'ipt type="text/javascript" src="' + arday[day] +'">');
document.write("</script>");
</script>
</body>
</html>
[/CODE]

and have them both saved in the same folder.

And i get Monday is Today printed on the page.
Copy linkTweet thisAlerts:
@Felix67authorJul 25.2005 — Genius! Thanks again for your patience, Bathurst_guy - you have done more than I ever could

I tried it in a .html as you said and it worked 100% as you said. I also replaced your monday.js with my own monday.js file and that also worked. Mmmm, well I need to go back to the drawing board why it is not showing up properly. I think maybe I will try moving the .js away from sub-directory and see if that helps...

Will keep you posted

Thanks again for your time :-)
×

Success!

Help @Felix67 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...