It's a very simple question but I couldn't figure it out. I'm trying to pass parameters to a Javascript function which is invoked when a hyper link is clicked.
It works just fine when the parameters are number but doesn't work when one of them is of type string. I even tried to escape them but unfortunately to no avail.
The following is a very simple code.
function temp(a, b)
{
alert(a+ +b);
}
<a href=javascript:void(0); onclick=temp(x, 2);>Click</a>
It doesn't work complaining x is undefined
x
is here onclick=temp(x, 2);
. When I modify the function something like this temp(1,2);
, it works and alerts as specified.
What might be the reason? What is the solution?