da******@yahoo.com wrote:
Hi. I'm relatively new to asp.net and very new to javascript. I'm
attempting to modify table cells after my page has loaded.
Then ASP is irrelevant. Just discuss the code at the client, how you
generate it at the server is for some other forum.
Here is the
javascript code within my asp.net page which runs OnLoad:
<script language="javascript">
language has been depreciated, use:
<script type="text/javascript">
function ShowGridHeader()
{
if (typeof grdData == "undefined")
{
alert("undefined")
}
This script does not define grdData anywhere, so it is undefined. Your
script will stop execution right there - at least that is what the
code instructs the browser to do and what both IE and Firefox did for
me.
else
{
alert("defined")
var rgWidths = new Array();
------> tblDataHeader.rows[0].cells.length =
grdData.rows[0].cells.length;
You can't set 'length'. It's like telling a tree how many apples
it has. ...cells.length will return the number of cells in a row (IE
will also return the number of cells in a table if asked), are you
trying to use it to tell the row to create that number of cells?
If so, this is not how to do it. Learn about document.createElement.
Where have you defined "tblDataHeader"? It seems to be a reference to
a table header (thead) element, but ... ?
To get a reference to an HTML element, give it an id, then get a
reference to it. Suppose your HTML looks like:
<table id="tblDataTable">
<thead id="tblDataHeader">
<tr onclick="alert(this.cells.length);">
<td>blah1</td>
<td>blah2</td>
</tr>
</thead>
<tbody>
<tr><td> </td><td> </td></tr>
</tbody>
</table>
You can get a reference to the thead by:
var tbleDataHeader;
if ( document.getElementById ) {
tbleDataHeader = document.getElementById('tblDataHeader')
} else if (document.all) {
tbleDataHeader = document.all['tblDataHeader'];
}
If you are trying to create an element (say a table element), use:
var elementRef = document.createElement('table');
I think it would be best if you say what you are trying to achieve,
since your script is pretty broken it's impossible to tell what you are
trying to do.
--
Rob