473,387 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Javascript setting timeout problem

Hello,

I have a problem on setting timeout in for loop.

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. function setOpacity (elem, val) {
  2. var z = document.getElementById(elem);
  3. z.style.opacity=val/100;
  4. z.style.filter = "alpha(opacity=" + val + ")";
  5. }
  6. function LiveSupport() {
  7. var x = document.getElementById('c_cover');
  8. var y = document.getElementById('c_popcontent');
  9. var z;
  10. var startOpacity = '0'; //int only
  11. var endOpacity = '70'; //int only
  12. var nowOpacity;
  13. var t = 0;
  14. x.style.position = 'absolute';
  15. x.style.top = '80px';
  16. x.style.left = '50%';
  17. x.style.marginLeft = '-325px';
  18. x.style.background = '#000';
  19. x.style.zIndex = '998';
  20. x.style.height = '676px';
  21. x.style.width = '650px';
  22. x.style.opacity=startOpacity/100;
  23. x.style.filter = "alpha(opacity=" + startOpacity + ")";
  24. for (z=startOpacity; z!=endOpacity; z++) {
  25. t++;
  26. setTimeout("setOpacity('c_cover', z);", t);
  27. }
  28. }
  29.  
When i run "LiveSupport();", i have received "z is not defined" error!

How to fix it?

Thanks
Aug 30 '10 #1

✓ answered by Dormilich

that’s right. "setOpacity('c_cover', z);" is not executed in the scope of LiveSupport() but of setTimeout()/window. thus it is not defined. you would have to use a Closure for that.
Expand|Select|Wrap|Line Numbers
  1. // untested
  2. setTimeout(function(){ setOpacity('c_cover', z); }, t);

2 2179
Dormilich
8,658 Expert Mod 8TB
that’s right. "setOpacity('c_cover', z);" is not executed in the scope of LiveSupport() but of setTimeout()/window. thus it is not defined. you would have to use a Closure for that.
Expand|Select|Wrap|Line Numbers
  1. // untested
  2. setTimeout(function(){ setOpacity('c_cover', z); }, t);
Aug 30 '10 #2
ok thanks, it works!
Aug 30 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Ratan | last post by:
How to control FTP connection (InternetConnect) timeout using WinInet API in C#. Can anybody provide me some code example or suggestion to solve above problem. /Ratan
1
by: ruca | last post by:
Hi, CONFIGURATIONS I have set a timeout for my application to 5 minutes. For that I use Session.Timeout = 5. In IIS Timeout the value is the default: 20 minutes and 90 seconds for ASP Script...
1
by: Hema S via DotNetMonster.com | last post by:
Dear All, Problem 1 ----------- I am using Sql Server for session state and setting the timeout property. But my session is not getting expired at all. Snippet <sessionState...
17
by: jensen bredal | last post by:
Hello, i'm struggling with a somehow badly understood session scenario. I provide acces to my pages based on form authentication using Session cookies. Som of my pages are supposed to be...
10
by: greenb | last post by:
Our asp.net web app uses a .NET component (DLL) in the bin directory to call several stored procedures back to back to perform updates. They don't return any data. Sometimes the total execution...
2
by: Rajesh.jain25 | last post by:
Hi, I am facing a problem of automatic session timeout problem and automatic session_end event fired. Case1: As I have analyzed I get to know that the default session timeout is 20 in...
0
by: naveed | last post by:
I have been using a webservices of a compnay in Visual Studio 2003 without any problem. But recently I started to work with webservices in Viusal Studio 2005. I am getting a very strange problem...
1
by: Young | last post by:
I am getting timeout problem in my VB.NET app. I've set the timeout value in webconfig and machine.config file and also set it within the application and still my app. timeout sooner that...
2
by: SriBhargav | last post by:
Hi, I've a question on setting timeout on console.readline() I would like the user to input something through Console.readline() in 5 secs. If there is no input in that time, I would like to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.