Welcome to WebmasterWorld Guest from 54.227.72.69

Forum Moderators: open

Message Too Old, No Replies

Multiple events one function

     
3:17 am on May 14, 2014 (gmt 0)

Junior Member

5+ Year Member Top Contributors Of The Month

joined:Mar 1, 2010
posts: 194
votes: 0


The following works with no problem:

element.oninput = go;
element.onchange = go;
...


But isn't there a shorter way to achieve the same result? Do we have to repeat the same line for each event?
1:16 pm on May 14, 2014 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts: 4988
votes: 12


You could create your own function to wrap these calls:

function onvalchanged(element, go) {
element.oninput = go;
element.onchange = go;
}
3:59 pm on May 14, 2014 (gmt 0)

Junior Member

5+ Year Member Top Contributors Of The Month

joined:Mar 1, 2010
posts: 194
votes: 0


Thanks for the answer! It gave me some ideas.