473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Insertting Row content for IE6

Google gave me many hits for ""HTMLTableElement insertRow", but no
practical examples.

Can someone give me the code to insert some _CONTENT_ into a specifc
row of a table?

Specifically, how could I insert this simple row into the third spot in
a table (that has a tbody already), WITHOUT using innerHTML?

<tr id="tree_row_3">
<td width="20" height="20">&nbsp;</td>
<td width="20" height="20">&nbsp;</td>
<td width="20" height="20">Cell 3</td>
<td colspan="7">Cell 4, with colspan!</td>
</tr>

Thanks to anyone who can help me with this,
Ann

Feb 7 '06 #1
6 3076
Giggle Girl a écrit :
Google gave me many hits for ""HTMLTableElement insertRow", but no
practical examples.

Can someone give me the code to insert some _CONTENT_ into a specifc
row of a table?

Specifically, how could I insert this simple row into the third spot in
a table (that has a tbody already), WITHOUT using innerHTML?

<tr id="tree_row_3">
<td width="20" height="20">&nbsp;</td>
<td width="20" height="20">&nbsp;</td>
<td width="20" height="20">Cell 3</td>
<td colspan="7">Cell 4, with colspan!</td>
</tr>

Thanks to anyone who can help me with this,
Ann

Assuming that your reference to the tbody is objTBody:

var objTRow3 = objTBody.insertRow(3);
/* "The new row is inserted immediately before the current indexth row
in this section. (...) This index starts from 0 and is relative only to
the rows contained inside this section"
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-93995626
*/
objTRow.id = "tree_row_3";
/* http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-63534901 */
for(var CellIterator = 0; CellIterator < 2; CellIterator++)
{
var objCell = objTRow3.insertCell(CellIterator);
/* http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-68927016 */
objCell.width = 20;
/* http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-27480795 */
objCell.height = 20;
/* http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-83679212 */
objCell.appendChild(document.createTextNode(" "));
};
var objCell3 = objTRow3.insertCell(2);
objCell3.width = 20;
objCell3.height = 20;
objCell3.appendChild(document.createTextNode("Cell 3"));

var objCell4 = objTRow3.insertCell(3);
objCell4.colSpan = 7;
/* http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-84645244 */
objCell4.appendChild(document.createTextNode("Cell 4, with colspan!"));
If the above does not work, load your code in a page and provide the url
in this thread.
I wish you could have simply kept your posts in the same, previous,
initial thread. Creating another thread breaks, fragments the discussion.

Gérard
--
remove blah to email me
Feb 7 '06 #2
Giggle Girl wrote:
Can someone give me the code to insert some _CONTENT_ into a specifc
row of a table?

Specifically, how could I insert this simple row into the third spot in
a table (that has a tbody already), WITHOUT using innerHTML?

<tr id="tree_row_3"> ... </tr>


Hi Ann,

If you want to do this in a pure DOM sort of way, without using
innerHTML, here's what to do.

First, use document.createElement("tr") to create your row and
document.createElement("td") to create each of your cells. For each
cell in the row, call appendChild(element) on the table row, passing
each TD in turn.

Now to set the content of the TDs, use
document.createTextNode("content").

So, basically:

row = document.createElement("tr");
row.id = "tree_row_3";

col1 = document.createElement("td");
col1.appendChild(document.createTextNode("&nbsp;") ;
row.appendChild(col1);

....

col3 = document.createElement("td");
col3.appendChild(document.createTextNode("Cell 3");
row.appendChild(col3);

Then, once you've done all that, just insert it in the appropriate
point in the table.

--
Joe Attardi

Feb 7 '06 #3
Gérard Talbot wrote:
If the above does not work, load your code in a page and provide the url
in this thread.


I just checked my code in a real page and it worked without error,
without problems, without an itch in Mozilla Seamonkey 1.5a, Firefox
1.5.0.1, Opera 9.0 beta 2 and MSIE 7 beta 2.

Gérard
--
remove blah to email me
Feb 7 '06 #4
Gérard Talbot wrote :

var objTRow3 = objTBody.insertRow(3);
/* "The new row is inserted immediately before the current indexth row
in this section. (...) This index starts from 0 and is relative only to
the rows contained inside this section"
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-93995626
*/


Oops. If it's the 3rd table row, then it should be

var objTRow3 = objTBody.insertRow(2);

instead. Anyway, even if you make a mistake there, the js console will
help you in reporting some index problem.

Gérard
--
remove blah to email me
Feb 7 '06 #5
Joe Attardi wrote :
Giggle Girl wrote:
col1.appendChild(document.createTextNode("&nbsp;") ;


That won't work. If you absolutely need to insert a non-breaking space,
then you must escape to unicode, like this:

col1.appendChild(document.createTextNode("\u00a0") ;

Gérard
--
remove blah to email me
Feb 7 '06 #6
> "Giggle Girl" <mi*******@gmail.com> wrote:
news:11*********************@g14g2000cwa.googlegro ups.com....

Google gave me many hits for ""HTMLTableElement insertRow", but no
practical examples.

Can someone give me the code to insert some _CONTENT_ into a specifc
row of a table?

Specifically, how could I insert this simple row into the third
spot in a table (that has a tbody already), WITHOUT using innerHTML?

<tr id="tree_row_3">
<td width="20" height="20">&nbsp;</td>
<td width="20" height="20">&nbsp;</td>
<td width="20" height="20">Cell 3</td>
<td colspan="7">Cell 4, with colspan!</td>
</tr>

Thanks to anyone who can help me with this,
Ann


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
var parent,clone,ckb;
function bink(x){
if(document.cloneNode && document.insertBefore){
parent = x.parentNode;
while(parent.tagName.toLowerCase()!='tr'){parent=p arent.parentNode;}
clone=parent.cloneNode(true);
ckb=(x.innerText)?x.innerText.replace(/\s+/g,' ').replace(/^\s+||\s+$/g,''):
x.textContent.replace(/\s+/g,' ').replace(/^\s+||\s+$/g,'');
}
switch (ckb) {
case 'Insert Before':
parent.parentNode.insertBefore(clone,parent);
break;
case 'Insert After':
parent.parentNode.insertBefore(clone,parent.nextSi bling);
break;
case 'Remove':
parent.parentNode.removeChild(parent);
break;
default:
alert('oh crap!');
}
}
</script>
<title></title>
<meta http-equiv="content-type" content=
"text/html; charset=windows-1252">
</head>
<body>
<table summary="" cellpadding="0" cellspacing="0" border="1">
<tr>
<td>Table Cell</td>
<td nowrap>
<button type="button" onclick="bink(this);">Insert Before</button>
<button type="button" onclick="bink(this);">Insert After</button>
<button type="button" onclick="bink(this);">Remove</button>
</td>
</tr>
<tr>
<td>Table Cell</td>
<td nowrap>
<button type="button" onclick="bink(this);">Insert Before</button>
<button type="button" onclick="bink(this);">Insert After</button>
<button type="button" onclick="bink(this);">Remove</button>
</td>
</tr>
</table>
</body>
</html>

--
BootNic Tuesday, February 07, 2006 1:42 PM

"Do not trust your memory; it is a net full of holes; the most
beautiful prizes slip through it."
*Georges Duhamel, The Heart's Domain*

Feb 7 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: jonathan.beckett | last post by:
Hi All, For the past few months I have been working on an open source Apache/PHP/MySQL content management system - and have recently made it available for download. It's still very much a...
0
by: jonathan.beckett | last post by:
Hi All, I have just made version 0.4.8 of the PluggedOut CMS Content Management System available for download - it's free, and covered by the GPL. It's still very much a work in progress...
0
by: Scott Abel | last post by:
For immediate release: The Rockley Group Content Management Workshop Series Coming to Atlanta, Seattle, Vancouver, Chicago, Washington, DC, Toronto, and Research Triangle Park Learn more:...
14
by: j1c | last post by:
How can I remove the content in between tags? I have a page that has several custom tags: <!--tag:1--> Content 1 <!--/tag:1--> <br> <!--tag:2--> Content 2 <!--/tag:2--> <br> <!--tag:3--> Content 3...
1
by: Richard | last post by:
http://dynamicdrive.com/dynamicindex5/linkinfo.htm Using the above script, I have a plan whereby when the main link is active, two different content swaps take place. Column A shows the main...
10
by: clintonG | last post by:
Can somebody direct me to documents or source that supports the use of collapsible content that is collapsed by default when the page is loaded? The secondary objective would of course be...
1
by: athirumurthi | last post by:
I have a WinINet communicating with an integration server (X-AspNet-Version: 1.1.4322) using form posts. One form post that includes jpeg content. However, the data received at the server is...
9
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.