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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing style attribute

Status
Not open for further replies.

lazyrunner50

Programmer
Joined
Jul 30, 2004
Messages
63
Location
US
I have a table whose cells I want to be able to change when the user rolls over them. I keep getting errors, and seeing as how IE is so helpful explaining what the errors are, I can't figure it out!! Here's what I have so far:
Code:
<a href="mySite.asp?somePassedVal=2" onMouseover=changeOpacity('dark', 'item2') onMouseout=changeOpacity('light', 'item2') > 
	<TD class='tableHeadingText' style='filter:alpha(opacity=70); cursor:hand' id='item2' BGCOLOR='#EBED3E'>
	    Blah, blah, blah
	</TD>
</a>
and here's the changeOpacity function
Code:
function changeOpacity(lightOrDark, theElement)
{
	if(lightOrDark = 'light')
		getElementByID("theElement").style = 'filter:alpha(opacity=70);'
	else	
		getElementByID("theElement").style = 'filter:alpha(opacity=90);'
}
 
Forgot to add..I know you are not really supposed to nest a td attribute inside an <a> tag. I tried changing the style from within the td tag, and that didn't work too well either. I could get it to switch pages (the retrievePage function) but the changeOpacity one would not.

Code:
<TD class='tableHeadingText' BGCOLOR='#EBED3E' style='filter:alpha(opacity=70); cursor:hand' onMouseover=changeOpacity('dark', this) onMouseout=changeOpacity('light', this) onClick=retrievePage(2)>
 
Damn, I tried to post this and got an error. It was a long post too. Here's just the code changes. Let me know if you have any questions:

Code:
<script language="javascript" type="text/javascript">
<!--
function changeOpacity(lightOrDark, theElement)
{
    if(lightOrDark = 'light')
        [blue]document.[/blue]getElementByI[blue]d[/blue]([blue]theElement[/blue]).style[blue].filter[/blue] = 'alpha(opacity=70);'
    else    
        [blue]document.[/blue]getElementByI[blue]d[/blue]([blue]theElement[/blue]).style[blue].filter[/blue] = 'alpha(opacity=90);'
}
-->
</script>

Code:
[blue]    <td class='tableHeadingText' id='item2'  onmouseover="changeOpacity('dark', 'item2')" onmouseout="changeOpacity('light', 'item2');">
        <a href="mySite.asp?somePassedVal=2">Blah, blah, blah</a>
    </td>[/blue]

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Hey. Thanks for the help! I'll try it when I get home from work. One problem with that though...I did not want just the text to be a link. I wanted the whole cell to function as a link. That is why I put the <a> tag on the outside of the cell. Do you know of any way to do that?
 
Yeah, use the onclick event of the <td>.

Wrapping block elements (td) with inline elements (a) is not acceptable html.

Code:
<td class='tableHeadingText' id='item2'  onmouseover="changeOpacity('dark', 'item2')" onmouseout="changeOpacity('light', 'item2');" onclick="document.location='mySite.asp?somePassedVal=2'";>
        <a href="mySite.asp?somePassedVal=2">Blah, blah, blah</a>
    </td>

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Still not working. Not getting any errors though! Here's what I have now:
Code:
<td class='tableHeadingText' id='item2' onmouseover="changeOpacity('dark', 'item2')" onmouseout="changeOpacity('light', 'item2')" onclick="document.location='mySite.asp?somePassedVal=2'" style='filter:alpha(opacity=70); cursor:hand' BGCOLOR='#EBED3E' ;>
    Blah, blah, blah
</td>
...and the JS function
Code:
function changeOpacity(lightOrDark, theElement)
{
	if(lightOrDark = 'light')
		document.getElementById(theElement).style.filter = 'alpha(opacity=70);'
	else	
		document.getElementById(theElement).style.filter = 'alpha(opacity=90);'
}
 
Code:
...
    if(lightOrDark [red]==[/red] 'light')
...

== means compare the values
= means set the value and return it

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
Geez...can't believe I missed that! Thanks, works perfectly now.
 
thanks chessbot. i found 999 out of 1,000 :)

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
congratulations!

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top