Use of 'this keyword' javascript in IE ?

Posted by Ron on Stack Overflow See other posts from Stack Overflow or by Ron
Published on 2010-04-11T19:51:09Z Indexed on 2010/04/11 19:53 UTC
Read the original article Hit count: 316

Filed under:
|
|
|
|

Is there a workaround for Internet Explorer to implement the functionality offered by 'this' javascript keyword to get the dom element that triggered the event?

My problem scenario is : I have a variable number of text fields in the html form, like

input type="text" id="11">
input type="text" id="12"> ..

I need to handle the "onchange" event for each text field, and the handling is dependent on the 'id' of the field that triggered the event. So far I understand that my options are: 1) attach a dedicated event handler for each text field. so if I have n fields, i have n different functions, something like:

input type="text" id="11" onchange="function11();">
input type="text" id="12" onchange="function12();">

but the text fields are added and removed dynamically, so a better way would be to have one generic function instead.

2) use the 'this' keyword like:

input type="text" id="11" onchange="functionGeneric(this);">
input type="text" id="12" onchange="functionGeneric(this);">

But this option does not work with Internet Explorer.

Can anyone suggest a work around for getting it work in IE or some other solution that can be applied here? Thanks.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about this