etienne_marais
Honorary Master
- Joined
- Mar 16, 2008
- Messages
- 15,093
In php/html you can do something like this:
in a loop:
<input type="button" onclick="javascript:ClickFunction(<?php echo $id; ?>);" />
If using javascript
var btnLike=document.createElement("button");
var f = "javascript:ClickFunction();";
btnLike.setAttribute("onclick",f); // successfully invokes ClickFunction when button is pressed
but
var btnLike=document.createElement("button");
var f = "javascript:ClickFunction("+userid+");";
btnLike.setAttribute("onclick",f); // invoke ClickFunction fails
What is the correct approach for adding parameters to ClickFunction ? As f is a string I assumed it would assign the onclick property in much the same way as onclick is defined in html ?
in a loop:
<input type="button" onclick="javascript:ClickFunction(<?php echo $id; ?>);" />
If using javascript
var btnLike=document.createElement("button");
var f = "javascript:ClickFunction();";
btnLike.setAttribute("onclick",f); // successfully invokes ClickFunction when button is pressed
but
var btnLike=document.createElement("button");
var f = "javascript:ClickFunction("+userid+");";
btnLike.setAttribute("onclick",f); // invoke ClickFunction fails
What is the correct approach for adding parameters to ClickFunction ? As f is a string I assumed it would assign the onclick property in much the same way as onclick is defined in html ?
