Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > setTimeout function problem

Reply
Thread Tools

setTimeout function problem

 
 
foolsmart2005@gmail.com
Guest
Posts: n/a
 
      11-28-2008
I am now writing a function that when a page is loaded, at intervals
of a certain seconds(e.g. 5 seconds), first row of a column will be
displayed, then after the second intervals, the second row of the
column will be displayed and so on. I think I need to use setTimeout
to do this. But I want to ask as the column is in div form, how can I
make it into javascript? for example.
<--code here-->
<div id="col">
<div id="row1">
<div id="row_image1"><img src="image path" alt=""/></div>
<div id="text1"><h1><a href="Media.html">title</a></h1>
<p>content</p>
</div>
</div>

<div id="row2">
<div id="row_image2"><img src="../image/mp3_icon2.png" alt=""/></
div>
<div id="text2"><h1><a href="Media.html">title</a></h1>
<p>content</p>
</div>
</div>
</div>

how to make it into javascript? can I do something var row1 =
document.write("<img src="..."")...etc?
 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      11-28-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I am now writing a function that when a page is loaded, at intervals
> of a certain seconds(e.g. 5 seconds), first row of a column will be
> displayed, then after the second intervals, the second row of the
> column will be displayed and so on.


Don't make tickers, the plague of the Web. It is a pull medium, not a push
medium. Users want to decide what they see and when they see it, and they
want to see only this, only then.

> how to make it into javascript? can I do something var row1 =
> document.write("<img src="..."")...etc?


No. Read the FAQ, and then please find another problem to solve with scripting.

<http://jibbering.com/faq/>


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
 
Reply With Quote
 
 
 
 
Doug Gunnoe
Guest
Posts: n/a
 
      11-28-2008
On Nov 28, 1:17*pm, "(E-Mail Removed)"
<(E-Mail Removed)> wrote:
> I am now writing a function that when a page is loaded, at intervals
> of a certain seconds(e.g. 5 seconds), first row of a column will be
> displayed, then after the second intervals, the second row of the
> column will be displayed and so on. *I think *I need to use setTimeout
> to do this. *But I want to ask as the column is in div form, how can I
> make it into javascript? *for example.
> <--code here-->
> <div id="col">
> * * * * <div id="row1">
> * * * * * * * * <div id="row_image1"><img src="image path" alt=""/></div>
> * * * * * * * * <div id="text1"><h1><a href="Media.html">title</a></h1>
> * * * * * * * * <p>content</p>
> * * * * * * * * </div>
> * * * * </div>
>
> * * * * <div id="row2">
> * * * * * * * * <div id="row_image2"><img src="../image/mp3_icon2.png" alt=""/></
> div>
> * * * * * * * * <div id="text2"><h1><a href="Media.html">title</a></h1>
> * * * * * * * * <p>content</p>
> * * * * * * * * </div>
> * * * * </div>
> </div>
>
> how to make it into javascript? *can I do something var row1 =
> document.write("<img src="..."")...etc?


Yes you can do it in JavaScript. And you can use the setTimeout to
accomplish part of it, but...

Are you providing dynamic content in the div's, content that has
changed since the page has loaded? Like Thomas mentioned a 'ticker',
or do you know all the text you want to include when the page is
loaded and this is just some kind of 'effect'?

If this is an 'effect', you can set the css style to your div's
initially with display:none and every five seconds change one to
display:block

http://www.w3schools.com/htmldom/met_win_settimeout.asp
http://www.w3schools.com/css/pr_class_display.asp

???

But, I'm not sure if this is what you are wanting to do.
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      11-28-2008
Doug Gunnoe wrote:
> If this is an 'effect', you can set the css style to your div's
> initially with display:none and every five seconds change one to
> display:block
>
> http://www.w3schools.com/htmldom/met_win_settimeout.asp
> http://www.w3schools.com/css/pr_class_display.asp


The quality of information provided by this Web site ranges from obsolete
to misleading to incomplete to factually incorrect. *Do not use* it as
reference material.

In this case (proven once again):

1. There are no pointers in ECMAScript implementations, there are object
references.

2. window.setTimeout() does not cause the script engine to wait before
executing the code or calling the referenced function. It has the UA
plan execution at a later time instead, then immediately continues
with evaluating the next statement.

3. window.setTimeout() does not have a third argument to specify the
scripting language in JavaScript or the Gecko DOM, only in the MSHTML
DOM. In JavaScript and the Gecko DOM, the third argument and further
arguments are used instead as arguments to the function call when you
pass a Function object reference for the first argument, and either are
ignored or throw an exception if you pass a string for the first
argument.

<https://developer.mozilla.org/en/DOM/window.setTimeout>

4. setTimeout() is defined a method of Window objects, not the ECMAScript
Global Object. It should not be called in a way that assumes a fitting
object is in the scope chain, but in a way that reduces the likelihood
to target the wrong object -- window.setTimeout(...) -- preferably
only after a feature test made sure that this object exists and that
object provides the method.

5. MSHTML-based UAs like Internet Explorer won't accept any `display'
values except `none', `inline', and `block'.

And probably I have overlooked other errors there.


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
 
Reply With Quote
 
Jorge
Guest
Posts: n/a
 
      11-28-2008
On Nov 28, 8:17*pm, "(E-Mail Removed)"
<(E-Mail Removed)> wrote:
> I am now writing a function that when a page is loaded, at intervals
> of a certain seconds(e.g. 5 seconds), first row of a column will be
> displayed, then after the second intervals, the second row of the
> column will be displayed and so on. *I think *I need to use setTimeout
> to do this. *But I want to ask as the column is in div form, how can I
> make it into javascript? *for example.
> <--code here-->
> <div id="col">
> * * * * <div id="row1">
> * * * * * * * * <div id="row_image1"><img src="image path" alt=""/></div>
> * * * * * * * * <div id="text1"><h1><a href="Media.html">title</a></h1>
> * * * * * * * * <p>content</p>
> * * * * * * * * </div>
> * * * * </div>
>
> * * * * <div id="row2">
> * * * * * * * * <div id="row_image2"><img src="../image/mp3_icon2.png" alt=""/></
> div>
> * * * * * * * * <div id="text2"><h1><a href="Media.html">title</a></h1>
> * * * * * * * * <p>content</p>
> * * * * * * * * </div>
> * * * * </div>
> </div>
>
> how to make it into javascript? *can I do something var row1 =
> document.write("<img src="..."")...etc?


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="jorge">
<!-- Date: 2008-11-28 -->

<script>
window.onload= function () {
function $ (p) { return document.getElementById(p); }
var div1S, div2S, ms= 5000;

(div1S= ($('row1').style)).display= "";
(div2S= ($('row2').style)).display= "none";

setTimeout(function f () {
div1S.display = div1S.display ? '' : 'none';
div2S.display = div2S.display ? '' : 'none';
setTimeout(f, ms);
}, ms);
};
</script>

</head>
<body>

<div id="col">

<div id="row1">
<div id="row_image1">
<img src="1.jpg" alt=""/>
</div>
<div id="text1">
<h1>
<a href="Media.html">ROW 1</a>
</h1>
<p>content</p>
</div>
</div>

<div id="row2">
<div id="row_image2">
<img src="2.jpg" alt=""/>
</div>
<div id="text2">
<h1>
<a href="Media.html">ROW 2</a>
</h1>
<p>content</p>
</div>
</div>

</div>

</body>
</html>

--
Jorge.
 
Reply With Quote
 
Doug Gunnoe
Guest
Posts: n/a
 
      11-28-2008
On Nov 28, 2:16*pm, Thomas 'PointedEars' Lahn <(E-Mail Removed)>
wrote:
> Doug Gunnoe wrote:
> > If this is an 'effect', you can set the css style to your div's
> > initially with display:none and every five seconds change one to
> > display:block

>
> >http://www.w3schools.com/htmldom/met_win_settimeout.asp
> >http://www.w3schools.com/css/pr_class_display.asp

>
> The quality of information provided by this Web site ranges from obsolete
> to misleading to incomplete to factually incorrect. **Do not use* it as
> reference material.


You're not the boos of me.

I'm sure w3schools has plenty of blunders and gaffes. It doesn't
concern me. It is well organized and easy to find what you're looking
for, especially when you're only really needing a function prototype
or a reminder of a property name and so forth...
 
Reply With Quote
 
David Mark
Guest
Posts: n/a
 
      11-28-2008
On Nov 28, 3:32*pm, Jorge <(E-Mail Removed)> wrote:
> On Nov 28, 8:17*pm, "(E-Mail Removed)"
>
>
>
> <(E-Mail Removed)> wrote:
> > I am now writing a function that when a page is loaded, at intervals
> > of a certain seconds(e.g. 5 seconds), first row of a column will be
> > displayed, then after the second intervals, the second row of the
> > column will be displayed and so on. *I think *I need to use setTimeout
> > to do this. *But I want to ask as the column is in div form, how can I
> > make it into javascript? *for example.
> > <--code here-->
> > <div id="col">
> > * * * * <div id="row1">
> > * * * * * * * * <div id="row_image1"><img src="image path" alt=""/></div>
> > * * * * * * * * <div id="text1"><h1><a href="Media.html">title</a></h1>
> > * * * * * * * * <p>content</p>
> > * * * * * * * * </div>
> > * * * * </div>

>
> > * * * * <div id="row2">
> > * * * * * * * * <div id="row_image2"><img src="../image/mp3_icon2.png" alt=""/></
> > div>
> > * * * * * * * * <div id="text2"><h1><a href="Media.html">title</a></h1>
> > * * * * * * * * <p>content</p>
> > * * * * * * * * </div>
> > * * * * </div>
> > </div>

>
> > how to make it into javascript? *can I do something var row1 =
> > document.write("<img src="..."")...etc?

>
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> * "http://www.w3.org/TR/html4/loose.dtd">


Why loose?

>
> <html lang="en">
> <head>
> * <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
> * <title>untitled</title>
> * <meta name="generator" content="TextMatehttp://macromates.com/">
> * <meta name="author" content="jorge">
> * <!-- Date: 2008-11-28 -->
>
> * <script>


No type?

> * window.onload= function () {
> * * function $ (p) { return document.getElementById(p); }


Why wrap this?

> * * var div1S, div2S, ms= 5000;
>
> * * (div1S= ($('row1').style)).display= "";


Why set this on load?

> * * (div2S= ($('row2').style)).display= "none";


This code is pretty illegible. At the very least, lose the "$".

>
> * * setTimeout(function f () {


Qualify that (window.setTimeout at least.)

> * * * div1S.display = div1S.display ? '' : 'none';
> * * * div2S.display = div2S.display ? '' : 'none';


Now this part could have used a function.

> * * * setTimeout(f, ms);


Why not use setInterval?

[snip]
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      11-28-2008
Doug Gunnoe wrote:
> Thomas 'PointedEars' Lahn wrote:
>> Doug Gunnoe wrote:
>>> If this is an 'effect', you can set the css style to your div's
>>> initially with display:none and every five seconds change one to
>>> display:block
>>> http://www.w3schools.com/htmldom/met_win_settimeout.asp
>>> http://www.w3schools.com/css/pr_class_display.asp

>> The quality of information provided by this Web site ranges from obsolete
>> to misleading to incomplete to factually incorrect. *Do not use* it as
>> reference material.

>
> You're not the boos of me.


Probably you meant to say *boss*. Of course I am not; I am a fellow
software developer, and what I said was meant as a strong and
well-intentioned recommendation.

> I'm sure w3schools has plenty of blunders and gaffes. It doesn't
> concern me.


Why do you insist to use bad information as reference when there are better
alternatives?

> It is well organized


Maybe so, but what good is good organization for if the organized content is
false?

> and easy to find what you're looking for,


There is other, better reference material that has this property as well.

> especially when you're only really needing a function prototype


You don't know what you are talking about.

> or a reminder of a property name and so forth...


You may ignore my recommendation at your own peril. Referring to inadequate
material here and thereby implicitly recommending it to others as reference
material is a different thing, though, for this newsgroup is not supposed to
be the place where blind are leading the blind -- on the contrary.


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
 
Reply With Quote
 
foolsmart2005@gmail.com
Guest
Posts: n/a
 
      11-29-2008
On Nov 29, 3:43*am, Doug Gunnoe <(E-Mail Removed)> wrote:
> On Nov 28, 1:17*pm, "(E-Mail Removed)"
>
>
>
> <(E-Mail Removed)> wrote:
> > I am now writing a function that when a page is loaded, at intervals
> > of a certain seconds(e.g. 5 seconds), first row of a column will be
> > displayed, then after the second intervals, the second row of the
> > column will be displayed and so on. *I think *I need to use setTimeout
> > to do this. *But I want to ask as the column is in div form, how can I
> > make it into javascript? *for example.
> > <--code here-->
> > <div id="col">
> > * * * * <div id="row1">
> > * * * * * * * * <div id="row_image1"><img src="image path" alt=""/></div>
> > * * * * * * * * <div id="text1"><h1><a href="Media.html">title</a></h1>
> > * * * * * * * * <p>content</p>
> > * * * * * * * * </div>
> > * * * * </div>

>
> > * * * * <div id="row2">
> > * * * * * * * * <div id="row_image2"><img src="../image/mp3_icon2.png" alt=""/></
> > div>
> > * * * * * * * * <div id="text2"><h1><a href="Media.html">title</a></h1>
> > * * * * * * * * <p>content</p>
> > * * * * * * * * </div>
> > * * * * </div>
> > </div>

>
> > how to make it into javascript? *can I do something var row1 =
> > document.write("<img src="..."")...etc?

>
> Yes you can do it in JavaScript. And you can use the setTimeout to
> accomplish part of it, but...
>
> Are you providing dynamic content in the div's, content that has
> changed since the page has loaded? Like Thomas mentioned a 'ticker',
> or do you know all the text you want to include when the page is
> loaded and this is just some kind of 'effect'?
>
> If this is an 'effect', you can set the css style to your div's
> initially with display:none and every five seconds change one to
> display:block
>
> http://www.w3schools.com/htmldom/met...ss_display.asp
>
> ???
>
> But, I'm not sure if this is what you are wanting to do.


Actually, this is an 'effect', but I am required to write by using
javascript. But the way, I changed a bit about the code Jorge post
but it's still not work.

<script type="text/javascript">
window.onload= function () {
<!--function (p) { return document.getElementById(p); }-->
var div1S, div2S, ms= 5000;

div1S= document.getElementById('row1').style.display= "";
div2S= document.getElementById('row2').style.display= "none";

setTimeout(function f () {
div1S.display = div1S.display ? '' : 'none';
div2S.display = div2S.display ? '' : 'none';
setTimeout(f, ms);
}, ms);
};
</script>

what is wrong with this code?
 
Reply With Quote
 
David Mark
Guest
Posts: n/a
 
      11-29-2008
On Nov 28, 9:49*pm, "(E-Mail Removed)"
<(E-Mail Removed)> wrote:

[snip]

>
> Actually, this is an 'effect', but I am required to write by using
> javascript. *But the way, I changed a bit about the code Jorge post
> but it's still not work.


http://www.jibbering.com/faq/faq_not...ml#ps1DontWork

[snip]
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use setTimeout function qasim ASP .Net 2 02-25-2009 05:48 PM
Function undefined problem? attempting to use setTimeout() to pause execution of functions. Noggon Javascript 1 06-24-2006 09:37 PM
Evaluating a Function After X Seconds: Python Equivalent to JavaScript's SetTimeout() Function ycoci0@gmail.com Python 3 06-12-2006 07:45 AM
Help with Passing an object to SetTimeOut function Ken Javascript 4 10-07-2004 11:29 AM
I have a problem with the setTimeout() function. Test Javascript 0 07-02-2003 11:14 AM



Advertisments