Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Location
    Now Southern Oregon. I was born and had lived my life in Los Angeles until relocating last year (2010)
    Posts
    215
    Thanks
    52
    Thanked 1 Time in 1 Post

    textarea processing problem

    I have a textarea:
    Code:
    <textarea class="norm" id="scrptExecEntry" name="scrptExecEntry" rows="10" cols="100"></textarea>
    Then I have javascript (as part of an object constructor function)
    Code:
    //.....
    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

  • #2
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    891
    Thanks
    174
    Thanked 102 Times in 102 Posts
    I THINK ta is a nodelist and so requires a loop

    eg

    Code:
    for (var i = 0;  i < ta.length; ++i){
      alert("Ta Class  "+ta[i].className); //norm
    }
    or this also worked for me

    Code:
    alert(ta[0].id); //scrptExecEntry
    LT
    Last edited by low tech; 04-02-2014 at 08:10 AM.
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.

  • Users who have thanked low tech for this post:

    anotherJEK (04-02-2014)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •