tag:blogger.com,1999:blog-31425501.post-40088592953289547432008-02-27T12:08:00.004-06:002008-03-11T11:12:46.025-05:00Save yourself the effort of defining the same code for multiple javascript eventsIf you ever have a situation where you basically want to run the same code for a bunch of different events on an html element like an input, it's a pain in the ass to maintain if you change the logic and need to change all of the event parameters. I discovered you can directly call another event so you don't have to define and maintain the same code in multiple places. I realize you can do something very similar by using addEventListener, but I just thought this was kind of cool.<br /><br />e.g.<br /><span style="font-style: italic;">// define the onchange event and call the same code for onmouseover, onmouseout, and onclick<br /></span><br /><span style="font-style: italic;">// Now if you make changes to onchange, you don't need to copy those changes to the other events.<br /></span><br /><br /><span style="font-style: italic;"><<span style="color: rgb(0, 0, 153);">input</span> ... <span style="color: rgb(153, 0, 0);">onchange</span>="<span style="color: rgb(0, 102, 0);">myFunctionDoYouLikeIt(this, 'valueadded', false, 0); compareSomeValues('placeholder', false, true, 'the google webz');</span>"<br /></span><br /><span style="font-style: italic;"><span style="color: rgb(153, 0, 0);"> onmouseover</span> = "<span style="color: rgb(0, 102, 0);">eval(this.onchange + '\;anonymous()\;');</span>"<br /></span><br /><span style="font-style: italic;"><span style="color: rgb(153, 0, 0);"> onmouseout</span> = "<span style="color: rgb(0, 102, 0);">eval(this.onchange + '\;anonymous()\;');</span>"<br /></span><br /><span style="font-style: italic;"><span style="color: rgb(153, 0, 0);"> onclick </span>= "<span style="color: rgb(0, 102, 0);">eval(this.onchange + '\;anonymous()\;');</span>" /></span>Jeremy "King Skidz" Gibbensnoreply@blogger.com