I was trying to pass a string to a JavaScript function.
As it\'s mentioned here - Pass a string parameter in an onclick function
I\'m using this simple co
Rename your variable name
to myname
, bacause name
is a generic property of window
and is not writable in the same window.
And replace
onclick='myfunction(\''" + name + "'\')'
With
onclick='myfunction(myname)'
Working example:
var myname = "Mathew";
document.write('');
function myfunction(name) {
alert(name);
}