Reply
changing table row colour on mouse over and out
Old 04-14-2008, 09:07 AM changing table row colour on mouse over and out
Experienced Talker

Latest Blog Post:
Long time no … erm post?
Posts: 45
Name: Matthew Bagley
hey guys, having some probs here for some weird reason my Javascript code isn't working how it should.

The idea is you can move the mouse over the table row and it will highlight the current row, now that works fine but I also want it so that if you click the row then it will change it to a darker colour which also works, now here is the trublesome part, when you moe the mouse away from this row then it should stay the same colour!

this is what I came up with
Code:
        if ($bgcolor == '#FFFFFF')$bgcolor = '#F3F3F3';
        else $bgcolor = '#FFFFFF';
?>
                <tr bgcolor="<?=$bgcolor;?>" onmouseover="if (this.bgColor = '<?=$bgcolor;?>'){this.bgColor = '#DDDDDD'} else {this.bgColor = '#CCCCCC';}" onmouseout="if (this.bgColor = '#DDDDDD'){this.bgColor = '<?=$bgcolor;?>'} else {this.bgColor = '#CCCCCC';}" onclick="this.bgColor = '#CCCCCC';">
but when you move the mouse out of the row that has been clicked on it resets the colour to the value of $bgcolor anyone have any ideas?

btw tried to put the onmouseover and that lot into a function but then it didn't work at all which i found totally weird
__________________
Matthew Bagley
Paramiliar Design Studios
Who am I | Free Layouts |Website Development | UK SEO
Paramiliar is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 04-14-2008, 10:59 AM Re: changing table row colour on mouse over and out
chrishirst's Avatar
Super Moderator

Posts: 11,866
Location: Blackpool. UK
Do we get to see a URL so we can see the code working (or not as the case may be)?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-14-2008, 11:05 AM Re: changing table row colour on mouse over and out
Christopher's Avatar
Iced Cap

Latest Blog Post:
Unicode and Character Sets
Posts: 3,108
Location: Toronto, Ontario
In your if you are using the assignment operator (=), you need to use the comparison operator (==).

Code:
if (this.bgColor == '<?=$bgcolor;?>')
Christopher is offline
Reply With Quote
View Public Profile Visit Christopher's homepage!
 
Old 04-14-2008, 12:00 PM Re: changing table row colour on mouse over and out
Experienced Talker

Latest Blog Post:
Long time no … erm post?
Posts: 45
Name: Matthew Bagley
I figured it out finally, I always use capital letters for HEX values (so #FFFFFF instead of #ffffff) for some reason javascript was reading this.bgColor as LOWER CASE letters and when I did the equalto it was upper case (if (#ffffff == #FFFFFF) ) which of course wouldn't work, change all the background colours to lower case and the **** thing works :@

btw here is the code if anyone wants it
Code:
<tr bgcolor="<?=$bgcolor;?>" onmouseover="if (this.bgColor == '<?=$bgcolor;?>'){this.bgColor = '#dddddd'} else {this.bgColor = '#cccccc';}" onmouseout="if (this.bgColor == '#cccccc'){this.bgColor = '#cccccc'} else {this.bgColor = '<?=$bgcolor;?>';}" onclick="if (this.bgColor == '#cccccc'){this.bgColor = '<?=$bgcolor;?>';} else {this.bgColor = '#cccccc';}">
__________________
Matthew Bagley
Paramiliar Design Studios
Who am I | Free Layouts |Website Development | UK SEO

Last edited by Paramiliar : 04-14-2008 at 12:31 PM. Reason: SOLUTION
Paramiliar is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to changing table row colour on mouse over and out
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13374 seconds with 13 queries