Reusing code in OnLoad and OnChange event handlers

Somtimes we need to execute the same set of twice once in OnLoad and in OnChange which calls for maintaining two set of codes or copying the same code for other. Again if there is some change in the first one we need to change the second one also.

Here is a simple implementation to avoid it. We will make use of the HTML DOM and include a function it, this function lives until the window is open accessable form all over the form.



var Hello = Function(){
alert("Say hello");
};


// now you can use somthng like this
window.Greet = Hello;

//or

window.Greet = function(){ alert("say hello"); };


To use it you can call this function from any location, like

// calling the function
window.Greet();