//adds the event handler when the page loads
onload = function() {
document.getElementById('turkey').setAttribute('onclick','testit()');
}
//clicking the link below will test if the attribute was set
function showevent() {
alert(document.getElementById('turkey').getAttribute('onclick'));
}
//clicking the button below will test if the event handler is working
function testit() {
alert('it works');
}
// if the input doesn't have an id, you can use the name instead
// document.forms[0].turkey.setAttribute('onclick','dofunction()');
<form>
<input type="button" id="turkey" name="turkey" value="TEST">
</form>
<br><br>
<a href=http://codingforums.com/archive/index.php/"javascript:showevent()">test</a>
