[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Update contents of a <tr> element using innerHTML

Posted on 2006-06-24
2
Medium Priority
?
1,215 Views
Last Modified: 2012-08-13
Hey guys,

I have a table I am generating, for each row I am currently also generating a form in another row with the same values. These two rows can be "toggled" between which means the "display" row is toggled off and the "edit" row is toggled on.

Generating a seperate form for each row was placing unnecessary load on the server so I wrote a function which generates the HTML source code for the "editing" form based on arguments passed to it, now the problem comes where I need to insert this generated code into the "edit" row.

I am aware of the problems associated with using innerHTML directly on <tr> elements in IE and had a solution which worked temporarily but now does not.

The javascript I am using is so:

      var tableEdit = document.getElementById("tableEdit" + id);
      try {
            tableEdit.innerHTML = tableEditHTML;
      }
      catch (e) {
              // IE fails unless we wrap the string in another element.
              var wrappingDiv = document.createElement('div');
            wrappingDiv.innerHTML = tableEditHTML;
              tableEdit.appendChild(wrappingDiv);
      }

This is being used on the following HTML:

      <table>
            <tr id="tableEdit'.$r['id'].'" class="toggleHide rowEdit">
            </tr>
      </table>

Note: The variable "tableEditHTML" contains <td> tags and when the function is called to populate the "tableEdit" row with HTML so is a function which switches the data display with the data editing rows.

The code works in Firefox but not in IE. I have verified that "tableEditHTML" is actually true.
0
Comment
Question by:shaggy_the_sheep
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
devic earned 1400 total points
ID: 16978936
hi shaggy_the_sheep, you can not use tr.innerHTML, so your tableEditHTML should be without <td>

here is an example what can you do:
=============================
<script>
function setMyHTML(curId)
{
      var tableEditHTML = "<b>hello</b> world!"
      var row = document.getElementById("tableEdit" + curId);
      if(row)
      {
            while(row.cells.length>0)
            {
                  row.deleteCell(0);
            }
            
            var cell = row.insertCell(0);
            cell.innerHTML = tableEditHTML;
      }
}
</script>
 <table border=1>
          <tr id="tableEdit5" class="toggleHide rowEdit">
          </tr>
 </table>
<button onclick="setMyHTML(5)">setMyHTML</button>
0
 
LVL 5

Author Comment

by:shaggy_the_sheep
ID: 16980416
Aaaah perfect! Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question