•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 422,662 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,683 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1536 | Replies: 8 | Solved
![]() |
I have created a timer function using setTimeout. The function works perfectly in IE and Opera but doesn't work in FireFox or Netscape 6. I checked out my Javascript book where it says setTimeout is compatible with all browsers. So where am I going wrong ?
The function reads an array of image paths and displays the images in different Image tags. With the timer the images automatically change after every 2 secs. Works fine in IE & Opera, doesn't work at all in FF and NN.
function showPics()
{
if (i > 4)
i = 0;
var index = i;
document.images("Img1").src = ImgBld[index];
index = index + 1;
if (index > 4)
index = index - 5;
document.images("Img2").src = ImgBld[index];
index = index + 1;
if (index > 4)
index = index - 5;
document.images("Img3").src = ImgBld[index];
index = index + 1;
if (index > 4)
index = index - 5;
document.images("Img4").src = ImgBld[index];
index = index + 1;
if (index > 4)
index = index - 5;
document.images("Img5").src = ImgBld[index];
index = index + 1;
if (index > 4)
index = index - 5;
i = i + 1;
setTimeout("showPics()",2000);
}The function reads an array of image paths and displays the images in different Image tags. With the timer the images automatically change after every 2 secs. Works fine in IE & Opera, doesn't work at all in FF and NN.
•
•
Join Date: Jan 2008
Location: Largo Florida
Posts: 269
Reputation:
Rep Power: 1
Solved Threads: 23
instead of accessing the images as collection items, use document.getElementById('imageID')
i dont know of opera but this works both in ie and firefox. Also since you are accessing the collection array, you might(i didnt try) use "[]" instead of "()". If you dont use document.getElementById method, try replacing the parathesis with brackets.
i dont know of opera but this works both in ie and firefox. Also since you are accessing the collection array, you might(i didnt try) use "[]" instead of "()". If you dont use document.getElementById method, try replacing the parathesis with brackets.
Serkan Şendur
MCAD.NET
MCAD.NET
•
•
Join Date: Jan 2008
Location: Largo Florida
Posts: 269
Reputation:
Rep Power: 1
Solved Threads: 23
•
•
•
•
I don't think you understood the problem. The problem has nothing to do with arrays or getElementById or brackets. The problem is setTimeout function is working in IE and Opera and not FF or NN. Otherwise the code is fine
I used setTimeout and it works both in ie and ff, www.altivi.com/shop go to the bottom of the page check if the lines get highlighted line by line. If it displays correctly, then this will be a proof that setTimeout works both in ie and ff, but i use latest version of firefox, what is your version?
Serkan Şendur
MCAD.NET
MCAD.NET
•
•
Join Date: Jan 2008
Location: Bangalore, India
Posts: 336
Reputation:
Rep Power: 0
Solved Threads: 32
hi
try this simple code it is working fine in both IE & FF:
try this simple code it is working fine in both IE & FF:
html Syntax (Toggle Plain Text)
<html> <head> <title> simple count down</title> <script language='javascript'> var i=0; var tid=0; function ut() { i++; document.frmT.txtB.value=i; tid=setTimeout("ut()",1000); } </script> </head> <body> <form name='frmT'> count down start now : <input type=text name='txtB'/> </form> <script> ut(); </script> </body> </html>
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.
~Mitch Ratcliffe
~Mitch Ratcliffe
•
•
Join Date: Jan 2008
Location: Bangalore, India
Posts: 336
Reputation:
Rep Power: 0
Solved Threads: 32
there might be problem in other lines u can check that by putting alert boxes between codes. if all are working then its fine.
u'r using () that could be problem use[], or better use getElementById()
coz setTimeOut() is compatible u can check my previous post.
u'r using () that could be problem use[], or better use getElementById()
coz setTimeOut() is compatible u can check my previous post.
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.
~Mitch Ratcliffe
~Mitch Ratcliffe
Thanks serkansendur and DangerDev. The problem was with the 'document.images(...)' part. I changed it to document.images[...] and it's working fine.
The display of '(' and '[' is almost similar in my Notepad font ('Bookman Old Style') so it was difficult to notice.
serkansendur, I apologise for my rather curt last message. You were absolutely right in pointing out the problem. My apologies
The display of '(' and '[' is almost similar in my Notepad font ('Bookman Old Style') so it was difficult to notice.
serkansendur, I apologise for my rather curt last message. You were absolutely right in pointing out the problem. My apologies
•
•
Join Date: Jan 2008
Location: Largo Florida
Posts: 269
Reputation:
Rep Power: 1
Solved Threads: 23
•
•
•
•
Thanks serkansendur and DangerDev. The problem was with the 'document.images(...)' part. I changed it to document.images[...] and it's working fine.
The display of '(' and '[' is almost similar in my Notepad font ('Bookman Old Style') so it was difficult to notice.
serkansendur, I apologise for my rather curt last message. You were absolutely right in pointing out the problem. My apologies
Add to my reputation so i will forgive you then
No problem, sometimes coding javascript makes me angry too. If you use visual studio .net,you can debug javascript although not as developed as debugging c#. Select tools >internet options > advanced in your ie browser window. In the advanced tab find "disable script debugging (internet explorer)", deselect the checkbox. Apply the changes then rerun your application in the debug mode. When javascript error occurs, internet explorer will ask you whether to debug the error. if you click yes then it will open up the visual studio editor and highlight the javascript line with the error notifying a simple error message like "null object" or "syntax error". Although not enough developed, this utility of visual studio makes javascript development easier. Serkan Şendur
MCAD.NET
MCAD.NET
> instead of accessing the images as collection items, use document.getElementById('imageID')
Actually it's the other way round. Instead of traversing the DOM tree it's better to use the images collection which holds a reference to all the images object in the document.
Actually it's the other way round. Instead of traversing the DOM tree it's better to use the images collection which holds a reference to all the images object in the document.
I don't accept change. I don't deserve to live.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- javascript works in IE but not working in firefox (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: setting values in dynamic buttons
- Next Thread: Adding custom tags to innerHTML



Linear Mode