473,473 Members | 1,723 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

settimeout needs alert() ???

Hi people,

Please take a look at the issue i talk about below. (yes i do realise such
functions are publicaly available)

The page i'm using uses JSON defined array of image files with
information for the title property of the img tag.

The functions i wrote below are sort of working since it needs an alert()
to work the slides ???

function slideshow ( dbname ) {

var dspitem = document.getElementById("bodybox");
var fotodb = eval(dbname);
var item = 0;
var dblength = dbname.length -3 ;

content = "<img src=img/foto/"+fotodb.foto[item].picture+" title="+fotodb.foto[item].name+" width=100% height=540px>";

slider ();

function slider () {
for (item = 0; item <= dblength; item++){ dspitem.innerHTML = "<img src=img/foto/"+fotodb.foto[item].picture+" title="+fotodb.foto[item].name+" width=100% height=540px>";
alert('temporary failure');
}

setTimeout ("slider();", 500);
}

}

Thank you for your advice and consideration.

Joris
Aug 7 '06 #1
1 1684

Joris Lambrecht wrote:
Hi people,

Please take a look at the issue i talk about below. (yes i do realise such
functions are publicaly available)

The page i'm using uses JSON defined array of image files with
information for the title property of the img tag.

The functions i wrote below are sort of working since it needs an alert()
to work the slides ???

function slideshow ( dbname ) {

var dspitem = document.getElementById("bodybox");
It helps greatly if you indent code with two or four spaces. The
easier you make it for others, the more likely you are to get replies.

var fotodb = eval(dbname);
A sample of the dbname file structure would help. The idea behind
using eval with JSON is that you retrieve the text using AJAX or
similar. In this case, why not just decalre it as a variable? You can
put it in a separate script file if you like, the use of JSON seems to
be just an excuse to use eval.

var item = 0;
var dblength = dbname.length -3 ;

content = "<img src=img/foto/"+fotodb.foto[item].picture+" title="+fotodb.foto[item].name+" width=100% height=540px>";

slider ();

function slider () {
By declaring slider() inside slidshow(), you make it local and hence
not available to calls made from the global scope (which is where
setTimeout runs from).

for (item = 0; item <= dblength; item++){ dspitem.innerHTML = "<img
src=img/foto/"+fotodb.foto[item].picture+" title="+fotodb.foto[item].name+" width=100%
Using innerHTML is less than optimal, create an img element in the HTML
and use script to replace the src and title attributes. Ensure a
default is loaded so anyone with script disabled or not available will
at least see something.

Also, you should quote attribute values - it's not always necessary and
some here argue you should only do it when it is, but it's much simpler
to just quote them always.

Finally, don't allow posted code to auto-wrap. Manually wrap it at
about 70 characters and ensure it 'works' (or at least displays the
issue) when copied and pasted into a test page.

height=540px>";
Each time the loop runs, it will completely replace the content of
dspitem. Considering it will run a few thousand times a second (at
least, in an average PC), the content is almost certainly replaced
before any of the images starts to download and therefore none of them
are downloaded completely (many will not even start to download).

alert('temporary failure');
This will cause each loop to pause and probably allow the screen to
update, hence you see the images.

}

setTimeout ("slider();", 500);
setTimeout runs in a global scope and so has no access to slider(),
which is local to slideshow(). You will get a 'slider is not defined'
error or similar.

The alert will make the script pause and display each image once, but
that's it.

}

}
The usual strategy is to load all of the images in to an array of image
objects, then use setTimeout to get the src attribute of an image in
the array and use it to change the src attribute of an image element
somewhere in the page.

Ensure that the image array object is persistant (e.g. make it global),
otherwise it won't properly preload the images.
--
Rob

Aug 7 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Robert Mark Bram | last post by:
Howdy All! How can I make something like this work? var message = "This will appear in 10 seconds"; setTimeout ('alert(message)', 10000); Thanks for any advice!
29
by: Mic | last post by:
Goal: delay execution of form submit Code (Javascript + JScript ASP): <% Response.Write("<OBJECT ID='IntraLaunch' STYLE='display : none' WIDTH=0 HEIGHT=0...
12
by: lkrubner | last post by:
Is there any reason why this code wouldn't prompt someone to save their work every 5 minutes? It doesn't seem to be working. This code shows up in the HEAD of an HTML document. function...
6
by: Brent | last post by:
Is there any obvious reason why there's no delay in the execution of setting the id.style.display when this function gets called? function Hide(divId,timeout) { var id =...
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
2
by: rain_c1 | last post by:
hi, i think this is a little exercise for real experts, but i suffer from real headaches because of it... :-\ i have an object method (method1), that calls setTimeout with an other method...
7
by: -Lost | last post by:
I am calling setTimeout within the context of an object, and whilst this exists, it refuses to be passed along to the function I call. For example: $elemById('id').change = function() { // the...
6
by: Steve | last post by:
I have noticed that setTimeout works if the brackets () are left off the function called, like this: window.setTimeout(myFunction, 1000); I thought that the brackets were required to show that...
19
by: liketofindoutwhy | last post by:
I did some animation using var oDiv = {}; oDiv.x = 100; oDiv.y = 100; oDiv.node = document.getElementById('divImage'); oDiv.node.style.position = "absolute"; oDiv.doAnimation = function()...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.