Passing A Java Variable To A Javascript Function
I have the following piece of code which is a input content for a js lib: content:'')' >
Solution 1:
content:'<ahref="x.com"onclick="confirmDel(\''+<%=user.name%>+'\')" ><imgsrc="delete.png"alt="Delete"width="15px"height="15px"></a></div>'
problem with passing parameter in the onclick..use escape character..
Solution 2:
confirmDel(name)
{
if(confirm("delete " + name +" ?"))
{
// Do delete stuff
} else
{
returnfalse;
}
}
This is incorrect. Its halfway between declaring a function and calling it, but doesn't really do either.
You need to declare the function and then call it to execute that code. You're calling it in the onclick section now, but you need to define it correctly
functionconfirmDel(nameStr)
{
if(confirm("delete " + nameStr +" ?"))
{
// Do delete stuff
} else
{
returnfalse;
}
}
Post a Comment for "Passing A Java Variable To A Javascript Function"