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 4 of 4
  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
    209
    Thanks
    52
    Thanked 1 Time in 1 Post

    Trouble with adding textNode

    I have written this code:
    Code:
    // this is part of constructor function
    this.mkNameHandler = function()
                   {
                    
                    this.groupName = document.forms.newCollection.newGroupName.value;
                    alert(this.groupName)
                    if(document.forms.newCollection)
                      {
                       var target = document.getElementById('record');
                       if(target)
                         {
                          var entry = document.createTextNode(this.groupName)
                              entry = "New Group Name: "+entry+"\n";
                          target.appendChild(entry); // <- THE LINE CAUSING THE ERROR
                         }
                      }
                    
                   }
    When this runs, the following error is posted to the Firefox v9.0 error console
    Error: uncaught exception: [Exception.... "Could not convert javascript arg 0
    [nsIDOMHTMLPreElement.appendChild]" nsresult:
    "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "js frame ::
    <page path> <TOP_LEVEL>:: line 46" data:no]
    I have another object method in the same constructor function that does
    virtually the same thing and does not crap out** (accept there is a gremlin
    that wants to assign text-align:center to pre tags that are assigned a css
    class rule without text-align assignment).

    THE QUESTION:
    So, any thoughts, suggestions?
    (Like why might this be happening?)
    **the code that does not cause the error
    Code:
    this.mkField = function()
                   {
                    // format index:fieldName/id, value:fieldType
                    if(document.forms.newCollection)
                      {
                       this.fieldList[document.forms.newCollection.fieldName.value] = document.forms.newCollection.fieldType.options[document.forms.newCollection.fieldType.selectedIndex].value;
                       var target = document.getElementById('record');
                       if(target)
                         {
                          var entry = "field name: "+document.forms.newCollection.fieldName.value+" - field type: "+document.forms.newCollection.fieldType.options[document.forms.newCollection.fieldType.selectedIndex].value+"\n";
                          var entry = document.createTextNode(entry) 
                           target.appendChild(entry);
                         }
                      }
    I am writing to pre tags because I don't want to bother with adding
    br tag elements, but want line breaks.
    Last edited by anotherJEK; 12-23-2013 at 06:31 AM. Reason: add Code sample

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    966
    Thanks
    19
    Thanked 211 Times in 209 Posts
    var entry = document.createTextNode(this.groupName)
    //entry is an object
    entry = "New Group Name: "+entry+"\n";
    adding the object entry to a string is an error

  • Users who have thanked DaveyErwin for this post:

    anotherJEK (12-23-2013)

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,273
    Thanks
    10
    Thanked 581 Times in 562 Posts
    replace
    Code:
          var entry = document.createTextNode(this.groupName)
                              entry = "New Group Name: "+entry+"\n";
    with
    Code:
          var entry = document.createTextNode("New Group Name: "+this.groupName+"\n");
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • Users who have thanked rnd me for this post:

    anotherJEK (12-23-2013)

  • #4
    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
    209
    Thanks
    52
    Thanked 1 Time in 1 Post

    Thanks for the info and suggestion

    Sometimes it helps to have another set of eyes look.


  •  

    Posting Permissions

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