Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
|
Ajax the combination of XHTML, CSS, DOM, XML, XSLT, XMLHttpRequest, and JavaScript
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Ajax section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 3rd, 2007, 05:02 AM
Registered User
 
Join Date: Apr 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Referencing new node in IE

Hi I have a problem in referencing new added node in IE.
My code is

newMessage = document.createElement("TR");
newMessage.setAttribute("ID","newrow");
document.getElementById("MessTable").appendChild(n ewMessage);
document.getElementById("newrow").innerHTML = "<TD>Data: " + dataMess + " Utente: " + userMess + "<BR><BR>" + cosaScrivere + "</TD>";


dataMess, userMess and cosaScrivere are function parameters.
In Firefox this code works, but in IE the last line returns this error:
"'document.getElementById(...)' is null or not an object" (I translate the error from italian).
Does it mean that I can't reference an added node in IE? There's another way?
If I explore DOM I can see the new <TR ID="newrow"> node.

Thanks for support
 
Old May 3rd, 2007, 10:59 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

innerHTML is read only in IE on table structures. You should use insertRow() and insertCell() to create tables, these work in IE and Firefox. Be careful to add the row or cell index as Firefox will error otherwise. Here's a fragment of code I wrote recently to create a table where the user adds or deletes rows:
Code:
      function addBookRow()
      {
        var oContainer = getBooksContainer();
        var oRow = oContainer.insertRow(oContainer.rows.length);
        var oCell = oRow.insertCell(0);
        oCell.appendChild(getNewTextbox(13, 13));
        oCell = oRow.insertCell(1);
        oCell.appendChild(getNewTextbox(13, 13));
        oCell = oRow.insertCell(2);
        var oButton = getNewButton("Remove Book");
        oButton.onclick = function(){deleteBookRow(this);};
        oCell.appendChild(oButton);
        oCell = oRow.insertCell(3);            
      }

      function getBooksContainer()
      {
        return document.getElementById("tbBooks");
      }

      function getNewTextbox(size, maxLength)
      {
        var oInput = document.createElement("input");
        oInput.type = "text";
        oInput.size = size;
        oInput.maxLength = maxLength;
        return oInput;
      }

      function getNewButton(value)
      {
        var oInput = document.createElement("input");
        oInput.type = "button";
        oInput.value = value;       
        return oInput;
      }

      function deleteBookRow(sender)
      {
        var oRow = sender.parentNode.parentNode;
        oRow.parentNode.parentNode.deleteRow(oRow.rowIndex);
      }

<table><caption>Add a Book</caption>
<thead><tr><th>ISBN</th><th>Pass Code</th>
<th>
<input type="button" value="Add Another Book" onclick="addBookRow();" /></th><th> </th></tr></thead>
<tbody id="tbBooks"><tr class="data"><td><input type="text" size="13" maxlength="13" /></td><td><input type="text" size="13" maxlength="13" /></td><td><input type="button" value="Remove Book" onclick="deleteBookRow(this);" /></td><td><span></span></td></tr></tbody>
</table>
--

Joe (Microsoft MVP - XML)
 
Old May 4th, 2007, 03:30 AM
Registered User
 
Join Date: Apr 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot for help!
Now it works






Similar Threads
Thread Thread Starter Forum Replies Last Post
The reference node is not a child of this node.XSL XMLUser XSLT 2 February 25th, 2008 05:22 AM
how to append child node after an node in XML + C# vishnu108mishra XML 5 November 13th, 2007 05:30 AM
Missing Node (Node data) pashworth XSLT 3 January 29th, 2007 12:39 PM
Copying Source Node attributes to output node pvsat XSLT 2 November 3rd, 2005 09:46 AM
document node order vs sort node order. ladyslipper98201 XSLT 2 June 5th, 2003 11:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.