Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 14th, 2005, 06:46 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I change a row colour with a checkbox?

Hello

I was wondering if someone could help me with the following problem...

I have some data from a database showing on screen - there are 3 rows of data (3 records). Within each row i have a checkbox. If the checkbox is 'ticked' i would like the row colour to change. If the checkbox is 'unticked' i would like the row colour to change back to the original colour.

Any idea how to do this? i'm not very hot on Javascript!

Thanks in advance

Lucy

Reply With Quote
  #2 (permalink)  
Old November 14th, 2005, 07:32 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

<script>

function highlight()
{

var el = document.getElementByID('picco')
el.style.backgroundColor = 'FFCC00';
}
</script>

<input type=checkbox name=highlight onclick=highlight();>
<tr id"picco">
<td>TEST</td>
</tr>


www.crmpicco.co.uk
Reply With Quote
  #3 (permalink)  
Old November 15th, 2005, 06:09 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hiya

I've tried this and it doesn't seem to work. I get an error on the line:

var el = document.getElementByID('picco')

Any ideas?

Cheers

Lucy

Reply With Quote
  #4 (permalink)  
Old November 15th, 2005, 06:22 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Lucy,

Try this...
Code:
<script language="javascript">
function HighlightRowIfChecked(checkBox){
    var bgColor = checkBox.checked ? "yellow" : "white";
    var el = checkBox.parentNode;
    while(el.tagName.toLowerCase() != "tr"){
        el = el.parentNode;
    }
    el.style.backgroundColor = bgColor;
}
</script>

...

<table>
    <tr>
        <td>text</td>
        <td><input type="checkbox" onclick="HighlightRowIfChecked(this);"></td>
    </tr>
</table>
HTH,

Chris

Reply With Quote
  #5 (permalink)  
Old November 15th, 2005, 08:53 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

you need to change the line:

<tr id"picco"> to
Code:
<tr id="picco">
www.crmpicco.co.uk
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Table row background colour changing meetravig Java GUI 0 September 21st, 2007 05:06 AM
Row colour change with Checkbox Toiletbrush Infopath 3 July 10th, 2007 06:25 AM
how to change the colour of a cell in a jtable Tomi Java GUI 1 April 25th, 2007 03:35 AM
change the colour of some particular rows bimal ADO.NET 1 September 10th, 2004 02:31 AM
Is there a way to change the colour of a tab ctrl? snowydust VB How-To 0 August 10th, 2004 01:39 AM



All times are GMT -4. The time now is 01:48 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.