I am trying to add a button from a javascript function (with the innerHTML method) that has another function as the onClick function. This onClick function has to take multiple parameters:
area.innerHTML += "<input type='image' src='images/del.jpg' width='15' height='15' " +
"onClick='del(" + info['_id'] + "," + key + "," + value + ")' />";
This is (I think) the most logical way to do this, but when I try to click the button there is no functioncall. This works with one single argument, so the problem has to be in the combination of the parameters with the ",". Does anybody know how to solve this?
update The del function is a temporary testfunction
function del(id, key, value) {
console.log(id + key + value);
}
delfunction?info[_id],keyandvalue?<button><img src="del.jpg"></button>is better than<input type="image">(but needs style hacks if you're forced to cater to IE6). Attaching event handlers from external JS is better than using inlineonclickhandlers. Inspecting the attributes and the DOM to find your id, key, and value is better than string concatenation. In summary, using your (JS) controller to manipulate your view (the DOM) is better than mixing the two together. IMHO. (my humble opinion is based on 20 years of event-driven programming. take it as you will.)