473,786 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ie6 Insert Row at specific Row Index of Table

Can someone show me how to insert a row at any given row index of an
already created table? It only has to work in IE6 (used on intranet at
work).

Specifically, if a table is 20 rows in total (thought his will vary),
and someone wants to insert a new row at row 5, i need for one row to
be added, and each of the rows from 5-20 to be "cloned" to 6-21.

The contents of row 5 may vary as well; it is not a straight copy of an
exisiting row.

I have seen something that did this very thing, but it used innerHTML,
and I have read this is inavisable for tables.

Thanks,
Ann

Feb 5 '06 #1
28 18538
Giggle Girl wrote:
Can someone show me how to insert a row at any given row index of an
already created table? It only has to work in IE6 (used on intranet at
work).

Specifically, if a table is 20 rows in total (thought his will vary),
and someone wants to insert a new row at row 5, i need for one row to
be added, and each of the rows from 5-20 to be "cloned" to 6-21.

Locate the table element in the DOM and use insertRow( index ) to insert
the row.

--
Ian Collins.
Feb 5 '06 #2
Ian Collins wrote:
Giggle Girl wrote:
Can someone show me how to insert a row at any given row index of an
already created table? It only has to work in IE6 (used on intranet at
work).

Specifically, if a table is 20 rows in total (thought his will vary),
and someone wants to insert a new row at row 5, i need for one row to
be added, and each of the rows from 5-20 to be "cloned" to 6-21.

Locate the table element in the DOM and use insertRow( index ) to insert
the row.


And be sure that you insert it as child element of a `thead' or `tbody'
element.
PointedEars
Feb 5 '06 #3
Thomas 'PointedEars' Lahn wrote:
Specifically , if a table is 20 rows in total (thought his will vary),
and someone wants to insert a new row at row 5, i need for one row to
be added, and each of the rows from 5-20 to be "cloned" to 6-21.


Locate the table element in the DOM and use insertRow( index ) to insert
the row.


And be sure that you insert it as child element of a `thead' or `tbody'
element.

Unnecessary and I think plain wrong, insertRow is an HTMLTableElemen t
method and it adds a tbody if the table is empty. Otherwise it will add
to the table section corresponding to the index.

Try this:

HTML:

<table id='test1'>
</table>
<table id='test2'>
<tbody>
<tr>
<td name='cell0'/>
<tr>
<tr>
<td name='cell1'/>
<tr>
<tbody>
</table>

Script:

var test1 = document.getEle mentById('test1 ');

test1.insertRow (-1);

alert(test1.inn erHTML);

var test2 = document.getEle mentById('test2 ');

var row = test2.insertRow (1);
var cell = row.insertCell(-1);
cell.name = 'cell2';

alert(test2.inn erHTML);

--
Ian Collins.
Feb 5 '06 #4
Ian Collins wrote:
Thomas 'PointedEars' Lahn wrote:
Specifically, if a table is 20 rows in total (thought his will vary),
and someone wants to insert a new row at row 5, i need for one row to
be added, and each of the rows from 5-20 to be "cloned" to 6-21.
Locate the table element in the DOM and use insertRow( index ) to insert
the row. And be sure that you insert it as child element of a `thead' or `tbody'
element.


Unnecessary and I think plain wrong, insertRow is an HTMLTableElemen t
method and it adds a tbody if the table is empty.


I remember to have read here that the latter does not happen in all DOMs,
especially I remember to have read here that it does not happen in the IE
DOM. Maybe I remember incorrectly.
Otherwise it will add to the table section corresponding to the index.

Try this:

HTML:

<table id='test1'>
</table>
This is not Valid (X)HTML. The `table' element requires at least the
`tbody' element in HTML, and although its start and end tags are optional
in HTML, its content model requires the `tr' element. In XHTML, the
content model of the `table' element requires at least one `tbody' or
one `tr' element.
<table id='test2'>
<tbody>
<tr>
<td name='cell0'/>
This is not Valid (X)HTML, `td' elements do not have a `name' attribute.
The SHORTTAG syntax used is equivalent to

<td name='cell0'>&g t;</td>

in HTML, and not recommended for XHTML per XML (as the `td' element is
not declared EMPTY there).
<tr>
<tr>
This is not Valid (X)HTML, the `tr' element's content model requires the
`th' or `td' element. In XHTML, the close tag is not optional.
<td name='cell1'/>
<tr>
See above.
<tbody>
</table>

Script:

var test1 = document.getEle mentById('test1 ');
test1.insertRow (-1);
These lack the previous feature test.
<URL:http://pointedears.de/scripts/test/whatami>
<URL:http://www.jibbering.c om/faq/faq_notes/not_browser_det ect.html>
alert(test1.inn erHTML); ^^^^^^^^^^
This is even more proprietary.
var test2 = document.getEle mentById('test2 ');
var row = test2.insertRow (1);
var cell = row.insertCell(-1);
cell.name = 'cell2';
alert(test2.inn erHTML);


An (X)HTML `td' element does not have a `name' attribute, and so
an HTMLTableCellEl ement object does not have a `name' property.
As DOM element objects are exposed as host objects to the script
engine, this has potential to break the script.

See above for the rest.
PointedEars
Feb 5 '06 #5
Locate the table element in the DOM and use insertRow( index ) to insert
the row.


And doing so will automatically "bump" all rows thereafter? (No need
for me to manually do it?)

If that is the case, awesome! If not, do you have some code I can see
that does it?

Thanks so much,
Ann

Feb 5 '06 #6
Thomas 'PointedEars' Lahn wrote:
And be sure that you insert it as child element of a `thead' or `tbody'
element.
Unnecessary and I think plain wrong, insertRow is an HTMLTableElemen t
method and it adds a tbody if the table is empty.

I remember to have read here that the latter does not happen in all DOMs,
especially I remember to have read here that it does not happen in the IE
DOM. Maybe I remember incorrectly.

If you'd tried the mickey mouse example (rather than pulling it apart)
you would have seen that it does work in IE (the OP's requirement).
<table id='test1'>
</table>

This is not Valid (X)HTML. The `table' element requires at least the
`tbody' element in HTML, and although its start and end tags are optional
in HTML, its content model requires the `tr' element. In XHTML, the
content model of the `table' element requires at least one `tbody' or
one `tr' element.

I don't care, it was a quick demo. The web is full of such
non-conforming code and browsers cope with it. If you try it, you will
see than IE automatically inserts the tbody.
alert(test1.inn erHTML);
^^^^^^^^^^
This is even more proprietary.

It's a demo for IE for goodness sake.

An (X)HTML `td' element does not have a `name' attribute, and so
an HTMLTableCellEl ement object does not have a `name' property.
As DOM element objects are exposed as host objects to the script
engine, this has potential to break the script.

That was a typo.

--
Ian Collins.
Feb 5 '06 #7
Giggle Girl wrote:
Locate the table element in the DOM and use insertRow( index ) to insert
the row.

And doing so will automatically "bump" all rows thereafter? (No need
for me to manually do it?)

Yes, as the name suggests, it inserts a row.

--
Ian Collins.
Feb 5 '06 #8
Thomas 'PointedEars' Lahn wrote:
Ian Collins wrote:

Thomas 'PointedEars' Lahn wrote:
>Specifical ly, if a table is 20 rows in total (thought his will vary),
>and someone wants to insert a new row at row 5, i need for one row to
>be added, and each of the rows from 5-20 to be "cloned" to 6-21.

Locate the table element in the DOM and use insertRow( index ) to insert
the row.

And be sure that you insert it as child element of a `thead' or `tbody'
element.


Unnecessary and I think plain wrong, insertRow is an HTMLTableElemen t
method and it adds a tbody if the table is empty.

I remember to have read here that the latter does not happen in all DOMs,
especially I remember to have read here that it does not happen in the IE
DOM. Maybe I remember incorrectly.


If adding rows using document.create Element() and appendChild(), some
browsers (e.g. IE) require that you append it to a tbody element - other
browsers (e.g. Gecko & KHTML based browsers) let you append it to the table.

However, insertRow() is a method of the HTMLTableSectio nElement. The
new row is created as a child of the table element, a append separate
append is not required.

<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-93995626>

[...]

--
Rob
Feb 5 '06 #9
VK

RobG wrote:
If adding rows using document.create Element() and appendChild(), some
browsers (e.g. IE) require that you append it to a tbody element - other
browsers (e.g. Gecko & KHTML based browsers) let you append it to the table.


Not totally right.
IE automatically creates at least one tbody element during the initial
page parsing. So either you added <tbody> tag or not you still have
tBody section and appendChild will add rows to there.
At the same time <thead> and <tfoot> elements are not created
automatically, so in order to insert rows to tHead or tFoot you have to
mark up your table in advance (or create header and footer
pragrammaticall y)

Other browsers do not create tBody automatically. On attempt to insert
a row to a table without <tbody> section three outcomes are possible:
1) the operation will fail
2) new row is added as direct child of table
3) on the first attempt to insert a row tBody section is created and
new row is added as a child if it (namely emulation of IE behavior).

While the 3rd one is currently the winning one, but all three outcomes
are still possible between different *rather modern* browsers and
versions.

This is why I'd like to repeat: if one plans to script a table, always
markup <thead>, <tfoot> and <tbody> manyally, do not trust the parser.

If you do not plan to script the table (add/remove/sort rows) then
<thead>, <tfoot> and <tbody> can be securely omited.

Feb 6 '06 #10

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

Similar topics

1
1540
by: Doron | last post by:
is there a setting that will ebnable uniform extent allocation upon creation of index/table by default ? if there isn't any default setting can you code it in? thanks, Doron
1
6069
by: Jay | last post by:
Hi I have a huge table with over 100million records and on regular basis ineed to delete nearly a million records and insert a million records. Currently I delete indexes before going through the process and recreate the indexes which takes a very very long time. IS there a way to disable indexes and re enable them after doing insert and delete by reindexing or anything of that sort? OR Is there an approach to append two tables with...
0
6891
by: crypto_solid via AccessMonster.com | last post by:
I have been using a SQL database with a VB5 frontend for about 5 years. Works well. Unfortunately I don't have access to the source code. I was tasked with implementing a "job entry" application that will allow a restricted list of users to enter jobs in the database. We do not want these users to be able to access all the data. I created an application in Access 2002 that performs this function seemingly quite well. However we now...
1
1553
by: Daniele | last post by:
Hi, how is it possible to create a full-text index table? Thanks, Daniele
1
1296
by: Bill Nguyen | last post by:
Below is the content of a textbox after data was captured from a barcode scanner. Instead of saving it into a text file and process later, I would like to be able to read the items (delimited by <CR>) and insert into a table. Please help show me an efficient way to do it. Thanks Bill
1
4561
by: technocraze | last post by:
Hi guys, I am having trouble resolving this error. Below mentioned is my code and implmentation. MS Acess is my front end and sql server is my backend. What i want to achieve is to be able to insert StudentId in the table matching the values chosen in the combo boxes and listboxes. This sound more like searching the table to insert StudentId matching the criterias. I have set the necessary configuration for ODBC connection (File...
7
14462
gcoaster
by: gcoaster | last post by:
Hello Gurus, I am stuck! this will be easy I am sure for you. I have a Text Box where I type In a name. I am trying to get that value to insert into another table when I TAB to the next field. Most of the INSERT code examples I find deal with multiple VALUES. could you point me in the right direction?
3
3174
by: grumpygit | last post by:
Hi. I am trying to get the columns in the navigation/index table to all be the same width on the page in link below. Code in attached .zip file Any advice would be greatly appreciated as I am a complete novice when it comes to CSS. Thanks. GG http://jinx.byethost13.com/template.php
1
1662
by: chennaibala | last post by:
hi frds... in my hiden textbox.i have following values... robert|true|true|false|arun|true|false|true|anu|true|true|false| i want to splits in to token and insert in mysql table in following manner namefield writefiled readfield speakfield robert true true false arun true false true anu true true false
1
2131
pradeepjain
by: pradeepjain | last post by:
Hii guys, I have 2 tables in which data exists of a same user like his table1:login details and table2: his further details . I have a form where in his both login and rest of details are collected. When i submit the form it needs to insert data in both the tables . Which is the best method to do it . insert into 1st table and if successful then insert into 2nd table ?
0
9650
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8992
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.