Onclick Dynamically Set

[Total: 0    Average: 0/5]

This example will change the onclick event handler by clicking on the set function 1 or set function 2 buttons

Body Code:

<script>
function fcnOne(){alert("Function One");}
function fcnTwo(){alert("Function Two");}
var _whatToDo= new Array();
    /* these numbers [1] and [2] must correspond with */
	/* the values in the doIt(#) in the form */
    _whatToDo[1]=fcnOne;
    _whatToDo[2]=fcnTwo;
function doIt(_f,_v)
{
  _f.b1.onclick=_whatToDo[_v];
  /* kill the button effect */
  return false;
}
</script>

<form name=exf1>
<input type=button name=b1 value="click me">
<HR>
<input value="Set Function 1" type=button onclick="return doIt(document.exf1,1)">
<input value="Set Function 2" type=button onclick="return doIt(document.exf1,2)">
</form>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *