Closed Thread Icon

Topic awaiting preservation: run function every 60 seconds? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8656" title="Pages that link to Topic awaiting preservation: run function every 60 seconds? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: run function every 60 seconds? <span class="small">(Page 1 of 1)</span>\

 
smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 05-16-2003 02:02

How do I make a function call repeat itself every 60 seconds and update the page display without refreshing/reloading the document? Is that a setTimeout thing? How does that work?

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-16-2003 04:28

learn to use google



.:[ Never resist a perfect moment ]:.

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 05-16-2003 04:55

Hum, this will be interesting to me.
Thanks.

Hiroki Kozai

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 05-16-2003 22:38

Thanks for the sarcasm-type wit there bitdamaged

Firstly, I wasn't sure what to search for on google,

Secondly, I tend to find things like that 'tutorial' overkill and still they don't quite make things clear for me.

In fact I still haven't got my function looping - basically it's an age finder script (you are 21 years

quisja
Paranoid (IV) Inmate

From: everywhere
Insane since: Jun 2002

posted posted 05-17-2003 00:26

The meat of this is almost entirely copied from that lycos page (although I knew about these things before, I just thought it might make more sense to you then).

function Age(variable, variable, variable) {

//the rest of your code here

//then this at the end will make it go back to the start of the function after 30secs
var the_timeout = setTimeout("Age();",30000);
}



bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-17-2003 00:56

Look I hate RTFM questions as much as anyone but for general questions like that it's better to try something and then give us a more specific problem than have us try to write a setTimeout tutorial that wouldn't be as good as something that has probably already been covered better by someone else.

I googled "setTimeout javascript" and that's the first thing I got. setTimeout alone was almost a better answer, both though are pretty good starts.

Using an external .js file is for all purposes the exact same as using inline javascript.

here's a simple loop

code:
function hello() {
if confirm("See this again?")) {
setTimout('hello()',5000);
}
}
hello();



That will loop until you hit no in the confirm box.

To change text, create it in a div with an id

<div id="myDIV">
</div>

Then change the text in there with innerHTML

document.getElementById('myDIV').innerHTML = "new text";


That's the basics but it's going to need more work to get it to work across all boundries

}
[/code]




.:[ Never resist a perfect moment ]:.

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 05-17-2003 01:22

quisja: I tried that already, but it didn't work so I thought I'd done it wrong. It doesn't work.

As I said before: 'Does text need to be in a text field to be 'updateable' or can it just be inline in a page (this is how I have it)?'

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 05-17-2003 04:27

bitdamaged: your version is working to some extent, but how do I get the function to loop the arguments that were submitted by the function call in the page? at the moment the arguments submitted from the page only go through the function the first time and then when the setTimeout thing starts the function again it throws out an error - if I leave the argument brackets empty then after the setTimeout thing kicks in the age turns into NaNs, and other way's I've tried don't work either.

Rather than use your innerHTML method and a div, I am using the same text area method as in the lycos demo.

I'm sorry for being dumb, but this is a rather weird thing to me (a newbie) however simple and basic it seems to you. If you (bitdamaged) get irritated about this post and me asking these things then just don't reply and let somebody else do it if they can be bothered.

I appreciate your help.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-17-2003 07:07

You need to pass the arguments to the function in the setTimeout But since it's a quoted string it gets a bit strange. I don't know what you have named the variables in your function so I'm guessing. What it should look like is this (I only went through day but you get the point)


myTimeout = setTimeout('Age(' +Year+ ',' +Mon+ ',' +Day ')',3000);



.:[ Never resist a perfect moment ]:.

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 05-17-2003 16:22

thanks bitty, that works great - I had tried that way myself, but never unquoted the variables/arguments in the string, it's these simple things that confuse newbies like myself.

« BackwardsOnwards »

Show Forum Drop Down Menu