0

I want to call the function getItemList() which is in a class 'Example' through addEventListener

var text_box = document.getElementById(this.text_box_id);
text_box.addEventListener('onchange', function(){this.getItemList('3', '10')}, false) 

1 Answer 1

1

It should be change, not onchange. Only in IE you have to use on(EventName).

this inside the handler will refer to text_box (the element the event was raised on). You have to capture a reference to the current this:

var that = this;
text_box.addEventListener('change', function(){    
    that.getItemList('3', '10')
}, false);

Or in browsers supporting bind (you can also provide your own implementation as shown in this documentation):

text_box.addEventListener('change', function(){    
    this.getItemList('3', '10')
}.bind(this), false);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.