• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

Change row color when checkbox is checked

This is part of a table I have. People are running reports and they have about 50 rown, they check the box for the item they want to include in the report. I want to change the background color of the row if the checkbox is checked and clear it back to white if they uncheck it. This way its a very visual way of seeing what is included in the report.

Page is classic ASP/VBScript

--
<table width="100%"  class="tablesample" id="results">
 <tr>
                        <td><div align="center">
                          <input name="chk_status" type="checkbox" class="bodytext" id="chk_status">
                        </div></td>
                        <td>Status</td>
                        <td><span class="bodytext">
                          <input name="statuscont" type="radio" value="0" checked>
Active
<input name="statuscont" type="radio" value="1">
Archived
<input name="statuscont" type="radio" value="%">
All </span></td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td><div align="center">
                          <input name="chk_type" type="checkbox" class="bodytext" id="chk_type">
                        </div></td>
                        <td>Type</td>
                        <td><span class="bodytext">
                          <input name="Contype" type="radio" value="1" checked>
Client
<input name="Contype" type="radio" value="0">
Prospect
<input name="Contype" type="radio" value="%">
All</span></td>
                        <td>&nbsp;</td>
                      </tr>
</table>

Open in new window

--

How can I do this ?  script ? css ?   Help is appreciated. We can use the example above. I assume I have to wrap the table row in a <div> then instruct the checkbox to change that specific row to change colors depending on its state ... :$
0
Aleks
Asked:
Aleks
  • 2
  • 2
1 Solution
 
Rainer JeschorCommented:
Hi,
a combination of both will do the trick.
Question: can you / are you willing to use the jQuery library?
That would make the scripting part much easier.
Thanks
Rainer
0
 
AleksAuthor Commented:
Sure, lets give it a shot :)
0
 
Rainer JeschorCommented:
Hi,
ok then please go to http://www.jquery.com and download an appropriate version.
Depending on your clients browser base either the latest 1.11.x version (for older browsers like IE 8) or the 2.x.y version (for newer browsers like IE10/11).

Then place the jquery file somewhere in your IIS site and add the following code (after adjusting the jquery path and file name) in the head section of your ASP page:
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$('#results').find('input:checkbox').click(function(){
			var isChecked = $(this).prop("checked");
			var $selectedRow = $(this).parent("td").parent("tr");
			if(isChecked) {
				$selectedRow.css({
					"background-color" : "black",
					"color" : "white"
				});
			} else {
				$selectedRow.css({
				   "background-color" : "white",
				   "color" : "black"
				});
			}
		});    
	});
</script>

Open in new window


HTH
Rainer
0
 
AleksAuthor Commented:
I am using DW CC and already using some JQuery elements so the include should already be there :)
Let me try and get back to you in a couple hrs.
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now