Reputation: 43
I have a html like this
<button class="btn btn-success" data-dismiss="modal"
onclick="updatepage(TestString)" data-toggle="modal">Test String</button>
and the function is
function updatepage(variable){
// some stuff
}
I'm getting an error "TestString is not defined", and if I put
onclick="updatepage("TestString")"
I get a syntax error.
Any ideas what I might be doing wrong?
Upvotes: 0
Views: 537
Reputation: 57709
onclick="updatepage(" + escape(JSON.stringify(TestString)) + ")"
You should consider using the EventListener API. This notation is limited to values that are easily serializable. You can not pass-by-reference, for instance.
Upvotes: 0
Reputation: 27584
You can use single quotes as string delimiters:
onclick="updatepage('TestString')"
Upvotes: 2