PDA

View Full Version : textarea processing problem



anotherJEK
04-02-2014, 07:27 AM
I have a textarea:


<textarea class="norm" id="scrptExecEntry" name="scrptExecEntry" rows="10" cols="100"></textarea>


Then I have javascript (as part of an object constructor function)


//.....
this.getTxtFieldIds = function()
{
var txt = document.getElementsByTagName('INPUT');
for(var i = 0; i < txt.length; i++)
{
if(txt[i].type == "text")
{
//alert(txt[i].id)
this.txtFieldIds[this.txtFieldIds.length] = txt[i].id+':text';
}
}
var ta = document.getElementsByTagName('TEXTAREA');
if(ta)
{
alert(ta.className)
var len = this.txtFieldIds.length;
this.txtFieldIds[len] = ta.id+':textarea';
alert(this.txtFieldIds[len]) // -> 'undefined:textarea'
}
else
{
alert(' no ta')
}
}
// .... etc

The problem is that the alert dialogs come up under if(ta) but ta.id is 'undefined';
I am probably having a fit of hysterical blindness but I can't see why.
All of the code for INPUT elements works as well as expected.
Thanks for time and attention

low tech
04-02-2014, 07:45 AM
I THINK ta is a nodelist and so requires a loop

eg


for (var i = 0; i < ta.length; ++i){
alert("Ta Class "+ta[i].className); //norm
}

or this also worked for me


alert(ta[0].id); //scrptExecEntry

LT