Reputation: 659
I'm having trouble adding in a variable into the following line of JavaScript:
row.insertCell(0).innerHTML = "<div onClick='Myfunction(" + Password + ");'></div>"
how do I add in the password variable I'm getting confused with apostrophes and double quotes
I think it needs to put the value in-between apostrophes but this clashes with what's already there?
Upvotes: 0
Views: 175
Reputation: 112
Try this example:
var Password ='sample';
document.getElementById("id1").value= '<div onClick="Myfunction(\'' + Password + '\');"></div>';
alert(document.getElementById("id1").value);
This is called Escaping. Use backslash() for the character which you want to escape.
Upvotes: 1
Reputation: 13380
you can try escape quotes with backslashes like this
row.insertCell(0).innerHTML = "<div onClick='Myfunction(\"" + Password + "\");'></div>"
Upvotes: 1
Reputation: 7367
Try this: row.insertCell(0).innerHTML = "<div onClick=Myfunction('" + Password + "');></div>"
Upvotes: 1