...

View Full Version : passing a param from a function to another



Kor
01-15-2004, 12:39 PM
I have some difficulties to pass a parameter.
I have some objects with same id, so I want to get them by order number let's say they are obj[i].

I call first function on an event onevent="one(0)" in a place, onevent="one(2)" and so on

function one(param){
obj[param].style.attribute ="blabla";
//so far so good, but from now once...

somevariable = setInteval('two(param)',somenumberhere);//here is a mistake, by sure... but which?
}

function two(param){
//no value passed???
alert(param);
obj[param]... and so on
}

I need the object in second function as well, but how can I pass the parameter in it?

Any ideeas, please?

Danne
01-15-2004, 12:57 PM
I suppose that param is a string. When you pass it to function one, it's only valid inside that function while setInterval executes code outside the functions. So put the value of param in setInterval instead:




setInterval('two("'+param+'")',somenumberhere);

Kor
01-15-2004, 01:02 PM
No, As I said, it is not a string... Anyway, I tryed, to be sure, the parseInt(param) but no use...:confused: . If I pass a definite number, yes, is OK, but I don't need to pass a certain value, I want to pass a value according to the event handler parameter....

Danne
01-15-2004, 01:20 PM
Sorry, maybe I should start reading more carefully :o

Let me first see if I got it now:
You have some elements with the same id, so they become a collection (ie-only?). The elementcollection is global.

So the only difference to what I wrote before would be to remove the double-quotes:



setInterval('two('+param+')',somenumberhere);



If you call function one:
one(0);

the setInterval should looks like this at runtime:
two(0);


Somehow it feels like I didn't understand this time either.

Garadon
01-15-2004, 01:27 PM
u tried writing:
setInterval
instead of:
setInteval
?

Kor
01-15-2004, 01:30 PM
Yeees Sir, I got it... Even it looks strange to me at the first glance to write something like

a_function('+0+')...

But I got the sense, thank you

liorean
01-15-2004, 03:32 PM
You could always have a look at <http://codingforums.com/showthread.php?s=&threadid=29568#post152688>. It's a method of doing things that might be a little hard to grasp, but it allows you to send things in other formats than as just a string.

Kor
01-15-2004, 04:06 PM
tack sa mycket, liorean... I saw that the main problem was not to pass a parameter, but to understand the setInterval() method



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum