Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
149
rated 0 times [  153] [ 4]  / answers: 1 / hits: 60721  / 11 Years ago, thu, august 8, 2013, 12:00:00

I want to make an eventHandler that passes this object as parameter. I tried this



 <select id=customer onchange=custChange(this);>


it works fine and get the the dom object on which on change even was called.



But as per my understanding this should not work as first argument is expected as event (not the this
object )in event handler method like below



  <select id=customer onchange=custChange(event);>


can we pass any argument(this or event) in eventHandler method provide their name is correct or first argument will
always be considered as event object?


More From » onchange

 Answers
10

You defined custChange and more importantly: you are calling it. Hence you can decide for yourself which arguments it should accept and in which order. Only for functions that are not called by you, you have to pay attention to the order of arguments.



But if you want to define custChange so that it is compatible with other ways of binding event handlers, i.e.



function custChange(event) {
// `this` refers to the DOM element
}


then you can call it with



custChange.call(this, event);

[#76467] Tuesday, August 6, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ravenl

Total Points: 338
Total Questions: 107
Total Answers: 112

Location: Belize
Member since Mon, Jun 20, 2022
2 Years ago
ravenl questions
Thu, Feb 18, 21, 00:00, 3 Years ago
Tue, Jan 12, 21, 00:00, 3 Years ago
Tue, Mar 17, 20, 00:00, 4 Years ago
;