473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Changing the background color of a table row when the User checks a checkbox

1
how i can change the color of row after selecting the checkbox
Aug 30 '07 #1
3 2150
nathj
938 Expert 512MB
how i can change the color of row after selecting the checkbox
Hi samiah,

I reccomend writing a javascript function for this. You can then call the function during the onclick of the check box:

[html]
<input type="checkbox" id="check1" value="yes" onclick="setColour(this.id, this.value);">
[/html]

The javascript function would be something like:
Expand|Select|Wrap|Line Numbers
  1. function setColour(elementID, elementValue)
  2. {
  3. if(elementValue == "yes")
  4. {
  5. var colour = "red" ;
  6. }
  7. else
  8. {
  9. var colour = "blue" ; 
  10. }
  11. document.getElementByID[elementID].innerHTML.colour = colour;
  12. }
  13.  
This is a little rough and you'd maybe want to set the colour better using RGB or Hex value. Also I'm not sure what element you want to change but this should at least give you a rough outline of how to use javascript to achieve what you are after.

Have a go and if you get stuck post back any code you have and I'll try to help some more.

Cheers
nathj
Aug 30 '07 #2
pbmods
5,821 Expert 4TB
Moving to the Javascript forum.

Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).
Aug 30 '07 #3
dmjpro
2,476 2GB
how i can change the color of row after selecting the checkbox
Welcome to TSDN!

Actually you better to come with some Code you have had.
Anyway, next time come with some codes.
Look at this code, it may help you!

Expand|Select|Wrap|Line Numbers
  1. <tr id = test_id><td><input type=checkbox onclick=setColor(this,'test_id')></td></tr>
  2.  
Expand|Select|Wrap|Line Numbers
  1. function setColor(obj,id)
  2. {
  3. var color = "#000000";
  4. if(this.checked) = "#FF0000";
  5. //If checked then Red otherwise Black.
  6. //I assumed that..You can do ur own choice.
  7. var row = document.getElementById(id);
  8. row.setAttribute("bgcolor",color);
  9. }
  10.  
I think it will work.
Try this.
Best of luck.

Kind regards,
Dmjpro.
Aug 31 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jason Dykes | last post by:
I have a page that is database driven. The pages shows a user's name and whether they have access to our site or not. this is done by displaying two checkboxes positioned to the right of the users...
3
by: Astra | last post by:
Hi All Could somebody confirm if and how I can change the TYPE of a textbox from PASSWORD to TEXT depending on whether a user checks a checkbox. In essence I have a login and password form and...
13
by: Gary | last post by:
I have a table with a form consisting of several checkboxes and I'm wondering if its possible to change the table row background color on mouseover or hover and make it stay that color when the...
7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
2
by: S P Arif Sahari Wibowo | last post by:
Hi! Do you know how to put a form's Access-Visual-Basic-code that will force the form to be inserted, while the user has not type anything in the form, without changing focus, selection, etc.? ...
2
by: zek2005 | last post by:
Hi!!!! I have a list of records as a result of a query. They are displayed with a while sentence... while($row = mysql_fetch_array($res)) at the end of each record, I inserted a checkbox...
15
by: phillip.s.powell | last post by:
<style> div div table tr td a.navbar, div div table tr td font {display: none;} </style> <div class="navigationbar" style="background-color:Black; position: absolute; left:50%; top:127px;...
1
by: DGI | last post by:
This may be very noob question but didn't found help anywhere: Could it be possible to have form checkboxes, everyone with different descriptive image laid out as a background near the box, via...
1
by: rbinington | last post by:
Hi, I am trying to write a DNN module that has the ability to insert articles into an article repository. I want the users to be able to move pages around and enter text into the FCKEditor. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.