Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Problem passing variables in function
Old 06-09-2008, 04:23 PM Problem passing variables in function
Truly's Avatar
Ultra Talker

Posts: 322
Trades: 0
I am having a hard time passing variables into functions. It works fine if I pass an integer but when I try and pass a variable it gives me an error. What am I doing wrong? When function newstimer(cur) tries to pass cur into the function change(cur) it "cur is undefined."

Code:
function newstimer(cur)
	{
	cur+=1;
	var t=setTimeout("change(cur);",2000);
	}
function change(cur)
	{
document.getElementById('mainNews').style.backgroundImage="url("+mainIMG[cur]+")";
document.getElementById('mainTitle').innerHTML = bigTitle[cur];
document.getElementById('mainTitleSmall').innerHTML = smallTitle[cur];
clearTimeout(t);
newstimer(cur);
	}
__________________
DVD Movie Release Database:
Please login or register to view this content. Registration is FREE
Truly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-10-2008, 11:03 AM Re: Problem passing variables in function
Skilled Talker

Posts: 62
Name: Tom Wright
Location: Brighton, UK
Trades: 0
You're passing setTimeout a string. This is correct, but it means you'll need to tinker.
I suggest changing
Code:
var t=setTimeout("change(cur);",2000);
to
Code:
var t=setTimeout("change("+cur+");",2000);
This means you'll pass the value of curr rather than the literal string 'curr'.

Hope this helps,
Tom
__________________
My site:
Please login or register to view this content. Registration is FREE
tomythius is offline
Reply With Quote
View Public Profile
 
Old 06-10-2008, 03:59 PM Re: Problem passing variables in function
Truly's Avatar
Ultra Talker

Posts: 322
Trades: 0
That worked perfectly thanks for the help. I had assumed that because it was in the bracket without any quotes just for itself that it wouldnt be a problem but obviously it was
__________________
DVD Movie Release Database:
Please login or register to view this content. Registration is FREE
Truly is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Problem passing variables in function
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.23704 seconds with 12 queries