Put it in quotes:
document.write("<a onclick=\"myFunc('"+id+"');\" href=#>Click me</a><br>");
// ---------------------------------^------^
FWIW, I strongly advise not using onxyz
-attribute-style event handlers. For one thing, the functions you call from them have to be globals, which is generally not a good thing. Instead, use modern event handling (addEventListener
, or attachEvent
on old IE; here's a function that handles that issue) or at least the onclick
property.
var id = "432.000+444";
var link = document.createElement("a");
link.onclick = myFunc.bind(link, id);
link.href = "#";
link.appendTextNode("Click me");
appropriateParentElement.appendChild(link);
appropriateParentElement.appendChild(document.createElement("br"));
function myFunc(id) {
alert(id);
}