
09-07-2007
|
| Senior Member
Join Date: Jun 2007
Posts: 1,413
BRL$: 4,235.66 Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 172 | | changes function dynamically 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 = ""; 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! To view links or images in this forum your post count must be 1 or greater. You currently have 0 posts. | |
__________________ To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts. | | | |