/    Sign up×
Community /Pin to ProfileBookmark

How to include this in a function?

Hello, I really need some help including this in a function. The function has a getElement by ID in it and thats whats throwing me off. The id calls on the nowDate and works just fine. Thing is I need to add
setTimeout(‘function()’,1000) to it somehow.

If I try to add the changeImg function to set Timout, within the changeImg function, as its usually done it won’t work due to the id element being in the function as well. I don’t know the best way to incorporate the setTimout so that when the id element is called it will utilize the set timeout along with the nowDate. Hope someone can help, heres the info. Thank you very much.

now = new Date()
nowDate = now.getMinutes()

function changeImg(){
document.getElementById(“img”).src = arr[nowDate-1][0];
}

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@CharlesOct 22.2006 — Please post the URL for what you have [i]and[/i] explain more clearly the problem.
Copy linkTweet thisAlerts:
@RiannaauthorOct 22.2006 — It works just fine on page load as usual. But I am trying to add setTimout to it so that

they change on their own after 1 minute. All the examples I have seen show setTimeout put at the end of the function with the function name included, like this.

function changeImg(){

document.getElementById("img").src = arr[nowDate-1][0];

setTimeout('changeImg()',1000);

}

But its not working. I am pretty sure its because id in the body is calling on the getElement Id in the function. If the body were calling on the changeImg function only

it would work. I don't know how to make it so getElementByID utilizes the setTimeout function as well as the nowDate variable. Thanks.
Copy linkTweet thisAlerts:
@CharlesOct 22.2006 — Perhapsfunction changeImg(){
document.getElementById("img").src = arr[new Date().getMinutes() - 1][0]
setTimeout('changeImg()',1000)
}
Copy linkTweet thisAlerts:
@RiannaauthorOct 22.2006 — My mouth just dropped way to the floor, you did it! Can you tell me why that made a difference? Isn't the the same thing as getting nowDate? Thank you very much! I'm very happy, I've been spending hours on this thing. I'll send you something.
Copy linkTweet thisAlerts:
@konithomimoOct 22.2006 — Getting the time by assigning it to variable nowDate outside of your function means that you will only get the time once . . . when the page loads. But by placing it inside of the function it gets the value every time. It wasnt that you were using nowDate, it was that you were assigning its value outside of the function. Then you simply have the function recurr on itself and you have what you want.
Copy linkTweet thisAlerts:
@KippodiOct 22.2006 — Hello all.
Copy linkTweet thisAlerts:
@KippodiOct 22.2006 — I found some nice tools, JavaScript Minimizer, IIS Log Parser, XML data editor. Take a look on site [URL=http://devtools.10try.com]devtools.10try.com[/URL] ?
×

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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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