Hi, i would like to add buttons, each with a different onclick function. I have 2 version of code, one of them workin in firefox while the other is not working at all:
the one working in firefox:
Code:
function addButton(aid, bit, value, onclick) {
var tmp = "<INPUT TYPE=button NAME='"+bit+"' ID='"+bit+"' onCLICK="+onclick+">";
parent.document.getElementById(aid).innerHTML += tmp;
}
the one not working at all:
Code:
function addButton(aid, bit, value, onclick) {
var tmp = document.createElement("input");
tmp.name = bit;
tmp.id = bit;
tmp.type = 'button';
tmp.value = value;
tmp.onclick = function() { onclick };
gE(aid).appendChild(tmp);
}
-aid is the id of the element that the button is going to be added to.
-bit is the name and id of the new button
-value is the value of the button
-onclick is a string that is suppose to be the function to be executed when the new button is clicked.
e.g. :
addButton('form1', 'button1', 'Alert me', "alert('You are alerted')";
addButton('form1', 'button1', 'Get value', "document.getElementById('textbox1').value='newval ue'");
Thanks in advance!