*Note With this technique, you can also change the onclick property after the button is clicked by using the this statement.
Code view
<div id="messageDiv" style="margin-bottom:5px;">Click the button below</div>
<input name="button1" type="button" id="button1" value="Click"/></div>
<script language="JavaScript" type="text/javascript" >
var myButton=document.getElementById("button1") ;
var doSomething=function()
{
document.getElementById("messageDiv").innerHTML="You clicked!" ;
this.onclick=function(){document.getElementById("messageDiv").innerHTML="You clicked again!" ;} ;
}
myButton.onclick=doSomething
</script>