var theForm = document.forms['theForm']; var theArea = document.createElement('TEXTAREA'); theArea.name = 'blabla'; theForm.appendChild(theArea); var out = theForm.elements['blabla']; window.asdasd = function() { out.value += ' asdasd'; } var newButt = document.createElement('INPUT'); newButt.type = 'button'; newButt.value = 'asdasd()'; newButt.onclick = asdasd; theForm.appendChild(newButt);