473,378 Members | 1,138 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,378 software developers and data experts.

setting outerHTML - can this be done?

Using IE 5.5 (sp2) - no other

I have a table that need's to be sorted by single column using javascript.

I have the code to do this but because of the attributes associated with the
<tr> element, when the sorted values are copied back in to the table I want
to replace the entire row not just the inner values!

Any ideas why this doesn't work?

var x = getElementByID('myTable'); //
def get's object successfully
alert(x.rows(0).outerHTML);
// before, shows current content
x.rows(0).outerHTML = "<tr><td>please work</td></tr>"; // Just to test,
but goes no further, no error just bombs out!
alert(x.rows(0).outerHTML);
// after

thanks

harry
Jul 23 '05 #1
4 17155
sorry didn't realise what mess it would look with comments -

var x = getElementByID('myTable');
alert(x.rows(0).outerHTML);
x.rows(0).outerHTML = "<tr><td>please work</td></tr>";
alert(x.rows(0).outerHTML); // never gets here
Jul 23 '05 #2
harry wrote:
Any ideas why this doesn't work?


IE doesn't let you set the innerhtml or outerhtml of td's or tr's. You also
can't set the innerhtml of a table. You can only set the outerhtml of the
full table itself.

If you want to manipulate table rows or cells, use DOM methods instead.
Or replace the entire table's outerhtml, which could be very slow.

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #3
VK
The Table Object Model cannot be manipulated in such way.

var myTable = getElementById('myTable');
var myRow = myTable.insertRow();
if (myRow != null) {
var myCell = myRow.insertCell();
myCell.innerHTML = '<b>It works !!!!!!!!</b>';
}
else {
window.alert('You can not change a data-bound table. You have to change the
data source itself');
}
More of useful reading:
http://msdn.microsoft.com/workshop/a...uildtables.asp

Jul 23 '05 #4
harry wrote:
sorry didn't realise what mess it would look with comments -

var x = getElementByID('myTable');
alert(x.rows(0).outerHTML);
x.rows(0).outerHTML = "<tr><td>please work</td></tr>";
alert(x.rows(0).outerHTML); // never gets here


Try using the DOM, it looks a but unweildy but it works.
You can replace individual TDs if you want, you can also use
cloneNode to make a copy of an element that contains a
complex set of other elements (much simpler than slabs of
createElement or innerHTML statements).

<script type="text/javascript">
function repRow(oldTR) {
var newTR = document.createElement('tr');
var newTD = document.createElement('td');
var newTX = document.createTextNode('Replacement text')
newTD.appendChild(newTX);
newTR.appendChild(newTD);
oldTR.parentNode.replaceChild(newTR,oldTR);
}
</script>

<table id="myTable" border="1">
<tr><td>Row above</td></tr>
<tr id="aRow"><td>Here is the current content</td></tr>
<tr><td>Row below</td></tr>
</table>
<form action="" name="aForm">
<input type="button" value="click" onclick="
repRow(document.getElementById('aRow'));">
</form>

Cheers, Rob.
Jul 23 '05 #5

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

Similar topics

3
by: Pai | last post by:
Hello there, I have the following peice of javascript which works with IE but would not work with mozilla. In IE the first for loop is entered but in mozilla i would not enter the for loop...
22
by: necromonger | last post by:
Hi, I've got this code that creates a new new row and cell. I then put some text into the cell with innerHTML - works beautifully with Firefox but fails with IE. I guess IE doesn't support this...
1
by: prasaddevivara | last post by:
I am using the outerHTML property to modify the HTML of existin elements in a web page in Internet Explorer. But same outerHTM property is not working in firefox browser, Anybody can tell me a...
0
by: schapopa | last post by:
I am exporting data to excel using VBScript: Dim sHTML sHTML = document.all.item("DataGrid1").outerhtml Dim oXL Dim oBook Dim oSheet Set oXL = CreateObject("Excel.Application") Set oBook =...
25
by: MeNotHome | last post by:
I am automating the navigation of a website. When I reach the end, it changes to xml. So my axwebbrowser1 has a bunch of xml data in it. So here is what I am trying to do Dim xmlText As...
3
by: David Virgil Hobbs | last post by:
I discovered how to write out the inner HTML of the contents of an Iframe; I want to know how to write out the outerHTML of the contents of an Iframe. frames.document.body.innerHTML allows me to...
1
by: cweeks | last post by:
Dev env: VS 2005 C# Express, .Net Framework 2.0 I am trying to programmatically select an item in a listbox on a web page. The first thing I do is go through and de-select any selected items. ...
1
by: rishabhshrivastava | last post by:
Hey All, I want to get the OuterHtml in a TextBox and I am using following code but I am getting value as "undefined" Please let me know if I am doing anything wrong.. function GetValue() {...
2
by: Smugsboy | last post by:
Hi, Got a problem here. I'm trying to create a bookmarklet on IE6, that passes the outerHTML of the body element as a GET param my site. The problem is that for some page (ie mail.yahoo.com) the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.