Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing the style of a row

Status
Not open for further replies.

fishiface

IS-IT--Management
Feb 24, 2003
687
GB
The code below fails with an "Object does not support this property or method" error under ie6. I think that the row does support a style property because I can set it statically. This makes me think that it is the [tt]getObjectById()[/tt] method which is failing but I cannot see why. Any enlightenment gratefully received.

[tt]
<html><head>
<script LANGUAGE=&quot;JavaScript&quot;>
function row( spec ) {
document.GetElementById('datum' + spec).style = 'background-color: red;';
return true;
}
</script>
</head>
<body>
<table border=1 width=&quot;30%&quot;>
<tr style='background-color: blue;' id='datum0'>
<td onClick='row(0);'>a</td>
<td onClick='row(0);'>1</td>
</tr>
</table>
</body>
</html>
[/tt]

Yours, &quot;As soon as we started programming, we found to our surprise that it wasn't as
easy to get programs right as we had thought. Debugging had to be discovered.
I can remember the exact instant when I realized that a large part of my life
from then on was going to be spent in finding mistakes in my own programs.&quot;
--Maurice Wilk
 
Two things are preventing this from working. (in my novice opinion!) Firstly, you are correct that getElementById does not appear to work. Changing this to document.all seems to be fine

Secondly, you have set a style to the row, and are changing this style. I found this will only work if you set a bgColor instead.

Try this code.

<html><head>
<script LANGUAGE=&quot;JavaScript&quot;>
function row( spec ) {
document.all('datum' + spec).bgColor=&quot;red&quot;;
return true;
}
</script>
</head>
<body>
<table border=1 width=&quot;30%&quot;>
<tr bgColor=&quot;blue&quot; id='datum0'>
<td onClick='row(0);'>a</td>
<td onClick='row(0);'>1</td>
</tr>
</table>
</body>
</html>
 
mwolf00's reply to a different thread has answered this for me. Thanks, mwolf00. &quot;As soon as we started programming, we found to our surprise that it wasn't as
easy to get programs right as we had thought. Debugging had to be discovered.
I can remember the exact instant when I realized that a large part of my life
from then on was going to be spent in finding mistakes in my own programs.&quot;
--Maurice Wilk
 
RikComery,

Thanks for replying. Your solution works as well. the one I got from mwolf00's post led me to write
[tt] document.GetElementById('datum' + spec).style.background = 'red';[/tt]
instead of
[tt] document.GetElementById('datum' + spec).style = &quot;background-color: 'red';&quot;[/tt]

Yours,
&quot;As soon as we started programming, we found to our surprise that it wasn't as
easy to get programs right as we had thought. Debugging had to be discovered.
I can remember the exact instant when I realized that a large part of my life
from then on was going to be spent in finding mistakes in my own programs.&quot;
--Maurice Wilk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top