/    Sign up×
Community /Pin to ProfileBookmark

How do I call on this .js file?

Hello, I found this online to change images daily. I have several images I would like to do this with so I want to make this an external javascript file instead of putting it in the source code because it will be real big.

I tried putting a regular .js call command in my web page to call it as I do with normal javascript functions but it doesn’t work. Seems to me I need a way to insert the image it selects into my page. Anyone know how? Thanks a lot. ? Rianna

<script>
<!– var mondayimg=”http://www.yourwebsite.com/yourgraphic.gif” var
tuesdayimg=”http://www.yourwebsite.com/yourgraphic.gif” var wednesdayimg=”http://www.yourwebsite.com/yourgraphic.gif
var thursdayimg=”http://www.yourwebsite.com/yourgraphic.gif” var fridayimg=”http://www.yourwebsite.com/yourgraphic.gif
var saturdayimg=”http://www.yourwebsite.com/yourgraphic.gif” var sundayimg=”http://www.yourwebsite.com/yourgraphic.gif
var mydate=new Date() var today=mydate.getDay() if (today==1) document.write(‘<img
src=”‘+mondayimg+'”>’) else if (today==2) document.write(‘<img
src=”‘+tuesdayimg+'”>’) else if (today==3) document.write(‘<img
src=”‘+wednesdayimg+'”>’) else if (today==4) document.write(‘<img
src=”‘+thursdayimg+'”>’) else if (today==5) document.write(‘<img
src=”‘+fridayimg+'”>’) else if (today==6) document.write(‘<img
src=”‘+saturdayimg+'”>’) else document.write(‘<img src=”‘+sundayimg+'”>’)
//–> </script>

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@konithomimoAug 07.2006 — just include it in your script tag:

<script type="text/javascript" src="myfile.js"></script>

just replace myfile.js with the file of your choics.
Copy linkTweet thisAlerts:
@RiannaauthorAug 07.2006 — Thanks, I tried that it didn't work.
Copy linkTweet thisAlerts:
@JMRKERAug 07.2006 — Be sure to remove ALL html tags in the ".js" file.

That means NONE! No <!-- -->. No <script ..></script>

No nothing of HTML in javascript file! ?

I've already made this mistake before, so fair warning. :o
Copy linkTweet thisAlerts:
@RiannaauthorAug 07.2006 — Already did that too. Is this not working because there needs to be some sort of command to tell the javascript file that the image needs to go right in a particular spot?

Since the script was written for all of it to be in the body section and I am trying to use it externally instead? Hope that makes sense.
Copy linkTweet thisAlerts:
@JMRKERAug 07.2006 — Can you call the script with a function NewDay()

and then onLoad='NewDay()' within the <body> tag?

[code=php]
function NewDay() {
var mydate=new Date()
var today=mydate.getDay()
if (today==1) document.write('<img src="'+mondayimg+'">')
else if (today==2) document.write('<img .......
.....
}

.....

<body onLoad="NewDay()">
[/code]


Would that work? ?
Copy linkTweet thisAlerts:
@RiannaauthorAug 07.2006 — I think your on the right track, I just don't know how to do it, hoping someone will.
Copy linkTweet thisAlerts:
@JMRKERAug 09.2006 — Try the suggestion just a posted.

The 'function NewDay() {' goes just after the <!-- tag

and the final '}' goes just before the //--> tag

Then put the call to the function as part of the <body> tag as shown.

See if that works. ?
×

Success!

Help @Rianna 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 4.27,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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