I need to pass two values to a javascript function from inside another javascript function as follows:
Something.innerHTML = Something.innerHTML + "<input type = 'submit' name = 'bbb' value = 'aaa' onclick = funcName(" + var1 + "," + var2 + "); />";
where: var1, var2 are two variables, whose values as shown by firebug are 2 and 3 respectively.
i) No error arises if I pass a single value, and the function receives a single value, i.e. funcName(var1)
ii) No error arises if I pass var1 twice, i.e. funcName(var1, var1);
iii) Error as reported by firebug when I pass var1, var2, i.e. funcName(var1, var2); is: missing ) after argument list and reports the following line: funcName(2,3
EDIT:
i) If I replace, ‘var1’, with any other variable, I am afraid the function does not work.
ii) I tried appending the two params using:
temp = var1 + “–” + var2;
And then ‘decoding’ it back in the receiving function, so that you could pass a ‘single’ parameter, but of no use.
You didn’t put quotes around the attribute. Moreover you shouldn’t use spaces: