|
-
Oct 22nd, 2002, 05:47 AM
#1
Thread Starter
Addicted Member
insertRow in Netscape 4.7
Hi,
Iam trying to insert a row in html table dynamically in a click of a button. Iam using ther following code.
Code:
<HTML>
<HEAD>
<STYLE>
.js {
color: white;
background-color: orange;
}
</STYLE>
<SCRIPT>
function addRowDOM (tableID) {
// pass every cell content as a futher arg
var table =
document.all ? document.all[tableID] :
document.getElementById(tableID);
if (arguments.length > 1) {
var row = table.insertRow(table.rows.length);
if (document.all) {
for (var i = 1; i < arguments.length; i++) {
var cell = row.insertCell(i - 1);
cell.innerHTML = arguments[i];
}
}
else if (document.getElementById) {
//NN6 bug inserting cells in wrong sequence
for (var i = arguments.length - 1; i >= 1; i--) {
var cell = row.insertCell(arguments.length - 1 - i);
cell.appendChild(document.createTextNode(arguments[i]));
}
}
}
}
function addRowHTML (tableID, html) {
if (document.getElementById && !document.all) {
var table = document.getElementById(tableID);
var tbody = table.tBodies[table.tBodies.length - 1];
var range = document.createRange();
range.setStartAfter(tbody.lastChild);
var docFrag = range.createContextualFragment(html);
tbody.appendChild(docFrag);
}
}
</SCRIPT>
</HEAD>
<BODY>
<BUTTON
ONCLICK="addRowDOM
('table1', 'JavaScript.FAQTs.com', 'www.FAQTs.com');"
>
add row per DOM methods
</BUTTON>
<BUTTON
ONCLICK="addRowHTML('table1',
'<TR><TD>JavaScript.FAQTs.com<\/TD><TD>www.FAQTs.com<\/TD><\/TR>');"
>
add row as html
</BUTTON>
<TABLE ID="table1" BORDER="1" CLASS="js">
<TBODY>
<TR>
<TD>
JavaScript.FAQTs.com
</TD>
<TD>
www.FAQTs.com
</TD>
</TR>
</TBODY>
</TABLE>
</BODY>
</HTML>
This works perfectly in IE5 and Netscape 6 and above.Is there any alternative method, so that I can get the same in Netscape 4.7?
Thanks,
Pres.
-
Oct 22nd, 2002, 06:18 AM
#2
Fanatic Member
I doubt you'll get it to work in Netscape 4 as its DOM is quite limited. You could try referencing the table using document.tables instead?
-
Oct 22nd, 2002, 11:21 PM
#3
Thread Starter
Addicted Member
Pls Explain
Hi,
Can you please explain this on how document.tables can be used.
Thanks,
Pres
-
Oct 23rd, 2002, 03:08 AM
#4
Fanatic Member
try replacing document.getElementById(tableId) with document.tables(tableId).
document.tables is a collection of all the tables in the document.
To be honest, I've never tried this is Netscape 4 but it may work.
-
Oct 23rd, 2002, 04:10 PM
#5
NS4.x won't allow it. You could only make that region a layer and rewrite the whole html of it using document.write
But who uses NS4 now anyway?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|