ycc
Feb 18th 2009, 5:42 pm
Hello guys,
Some time ago I got good help with the setTimeout function (by member lp1051). I kept following the pattern he adviced me to follow and it works well. However, I have some problems understanding it and this sometimes gives me trouble when I make changes to the code.
The situation occurs when I pass a function with variables to the setTimeout function.
In the following example span_up_box is the function I have written. It takes the following arguments: one string variable (szDivID) followed by four numerical variables. At least that is how I look upon the variable types, maybe my misunderstanding lies here.
However when I pass the arguments of the function span_up_box to setTimeout I MUST INCLUDE THE FIRST VARIABLE IN SINGLE QUOTES ('). I don't understand why. It is a string-variable that can take different values. (It is not a string but a variable name.)
However, the rest of the arguments are also variables, but these do NOT have to be included in single quotes.
window.setTimeout("span_up_box('" + szDivID + "', " + final_x + ", " + final_y_lift + ", " + final_width + ", " + final_height + ")", 12);
I can also put EVERY variable in single quotes and it works:
window.setTimeout("span_up_box('" + szDivID + "', '" + final_x + "', '" + final_y_lift + "', '" + final_width + "', '" + final_height + "')", 12);
(But readability is not so good, at least not to me.)
Thanks for advice.
Some time ago I got good help with the setTimeout function (by member lp1051). I kept following the pattern he adviced me to follow and it works well. However, I have some problems understanding it and this sometimes gives me trouble when I make changes to the code.
The situation occurs when I pass a function with variables to the setTimeout function.
In the following example span_up_box is the function I have written. It takes the following arguments: one string variable (szDivID) followed by four numerical variables. At least that is how I look upon the variable types, maybe my misunderstanding lies here.
However when I pass the arguments of the function span_up_box to setTimeout I MUST INCLUDE THE FIRST VARIABLE IN SINGLE QUOTES ('). I don't understand why. It is a string-variable that can take different values. (It is not a string but a variable name.)
However, the rest of the arguments are also variables, but these do NOT have to be included in single quotes.
window.setTimeout("span_up_box('" + szDivID + "', " + final_x + ", " + final_y_lift + ", " + final_width + ", " + final_height + ")", 12);
I can also put EVERY variable in single quotes and it works:
window.setTimeout("span_up_box('" + szDivID + "', '" + final_x + "', '" + final_y_lift + "', '" + final_width + "', '" + final_height + "')", 12);
(But readability is not so good, at least not to me.)
Thanks for advice.