
It's been some time since I posted on here and I thought this was cool, so I thought I'd share it with anyone who cares to use it.
I recently had a project that I was working on where the user is presented with a collection of records in a table format, and they can select rows in that table with a checkbox in each row. Like so:
| First Name | Last Name | |
|---|---|---|
| Fred | Flintstone | |
| Mickey | Mouse | |
| Daffy | Duck |
tr.selected {
background-color: #DAEFF1;
}
JavaScript:
function ToggleSelected(sender) {
var tr = sender.parentNode;
while (tr.nodeName.toLowerCase() != 'tr') { tr = tr.parentNode; }
tr.setAttribute('className', (sender.checked ? 'selected' : ''));
tr.setAttribute('class', (sender.checked ? 'selected' : ''));
}
You can see by reading through the JavaScript that all it does is find the containing TR element and toggle the class (or classname for IE) to "selected" or nothing depending on the status of the checkbox.
Once I had that function written, I just added a call to it in the onclick event in each checkbox, passing the checkbox itself as the sender: onclick="ToggleSelected(this)"
Now I have a nice highlight for each row when they are checked:
| First Name | Last Name | |
|---|---|---|
| Fred | Flintstone | |
| Mickey | Mouse | |
| Daffy | Duck |
Looking for our SharePoint development site? Look no further.
Not looking for it? Maybe you should be. Infotekka specializes in Microsoft SharePoint 2010 architecture, installation, configuration, and most importantly customization. If you'd like to know more please send us a note from the contact page.
The time has come to retire this website and implement a new one. We're likely going to stick with the same look and feel but it's moving off of it's current LAMP environment and going into .NET, where we can take advantage of all the fun integration stuff we're always crowing to our clients about.
Stay tuned for updates!