I am having trouble with my script in IE(IE6) and how it treats a "this". I am thinking it might have something to do with my event wrapper function(see code) but would like to keep that wrapper.
-
function BuildIt()
-
{
-
var taA=document.getElementById("taArea");
-
var soA=document.getElementById("soArea");
-
if((taA!=undefined)&&(soA!=undefined))
-
{
-
for(var i=0;i<NumberOfBoxes;i++)
-
{
-
var taObj = document.createElement('textarea');
-
with(taObj)
-
{
-
cols="24";
-
rows="6";
-
id="ta"+i.toString();
-
}
-
taA.appendChild(taObj);
-
AddEventWrapper(taObj,"change",function(evt){ReCalc(this);});
-
}
-
}
-
-
function AddEventWrapper(myElement,evtName,evtAction)
-
{
-
if(document.addEventListener)
-
{
-
myElement.addEventListener(evtName, evtAction,false);
-
}
-
else if(document.attachEvent)
-
{//prepend the "on" to the event
-
myElement.attachEvent("on"+evtName,eval(evtAction));
-
}
-
}
-
-
function ReCalc(o)
-
{
-
-
if(o!=undefined)
-
{
-
alert(o==document);
-
}
-
}
-
-
Now, in FF, everything is fine, ReCalc gets passed the correct instance of a textarea, in IE however it's always the document object itself.
I have tried many combinations for the line:
AddEventWrapper(taObj,"change",function(evt){ReCal c(this);});
Such as sending in the taObj, the id string for the current taObj, using eval in various places etc. All of those met with the same result, no matter which textarea i wrote in, it was always the last one that thought it was doing something.
Is there anyway to get the correct object to be passed into the event handler function in both IE and FF?