View Full Version : passing multipule parameters in a string

Graeme Hackston
02-28-2003, 02:49 AM
How would I also pass a variable that is a number in the follow example?

timer = setInterval("myfunction('"+string+"')", 1000)

02-28-2003, 02:53 AM
timer = setInterval("myfunction('"+string+", 2')", 1000)

Graeme Hackston
02-28-2003, 02:54 AM
Sorry John, I edited my question while you were posting but I'll give this a try

Graeme Hackston
02-28-2003, 03:01 AM
No I should have been more clear the first time. I want to pass 2 variables, ones a string the other a number (which now I'm thinking doesn't matter).

02-28-2003, 03:11 AM
timer = setInterval("myfunction('"+string+"',"+number+")", 1000)

Graeme Hackston
02-28-2003, 03:15 AM
Perfect, thanks guys. I'll have to stare at this until it makes sence :)

02-28-2003, 03:43 AM
if you are passing a reference to a form field:

timer = setInterval("myfunction(document."+obj.form.name+"."+obj.name+")", 1000)

where obj is the variable that referenced to a form field.

Graeme Hackston
02-28-2003, 03:51 AM
Cool, thanks Glen, I can actually read that one but never would have thought of it. In the 1st example you posted, why are the single quotes only around the first parameter?

Graeme Hackston
02-28-2003, 03:54 AM
Ok I think I've got it, it does matter whether it's a string or number

02-28-2003, 06:38 AM
yes, you're right.

if the values of the variable string and number have these values:

string = 'blah';
number = 1;

executing this:

timer = setInterval("myfunction('"+string+"',"+number+")", 1000)

would look like:

timer = setInterval("myfunction('blah',1)", 1000)

Graeme Hackston
03-01-2003, 01:45 AM
Thanks for the visual Glen. Now I can see exactly why.