Making your tables more accessible?
A question was asked on the display tag user list recently. Basically, the user wanted to add onmouseover and onmouseout events to the <tr>'s in a display-tag rendered table. Today, I decided to whip up a quick example of how to do this in a DOM-compliant browser. Just add an "id" attribute to your table, or use document.getElementsByTagName("table")
(selecting the appropriate table in the array), and then put the following JavaScript block below your table. Of course, you must define a "tr.over" class in your CSS.
<script type="text/javascript">
var table = document.getElementById("testTable");
var rows = table.getElementsByTagName("tr");
for (i=0; i < rows.length; i++) {
rows[i].onmouseover = function() { this.className='over' };
rows[i].onmouseout = function() { this.className='' };
}
</script>
Now for an example:
Later: You can take this one step further and add an "onclick" event so that the user can edit the record the row is referring to. Let's pretend you have a link in the first <td> of the table. Inside this link is the recordId for that row. Adding an onclick to the row makes it easy to route the user to the details page for the record.
rows[i].onclick = function() {
var cell = this.getElementsByTagName("td")[0];
var link = cell.firstChild;
var id = link.firstChild.nodeValue;
location.href='URL to details page?recordId='+id;
this.style.cursor="wait";
}
Posted by Guus on April 23, 2003 at 02:46 AM MDT #
Posted by Matt Raible on April 23, 2003 at 04:41 AM MDT #
Posted by Benjamin Simpson on October 28, 2003 at 02:57 PM MST #
Didn't know that you can change event handlers dynamically in html. Hope this works on both, Mozilla and IE....
Posted by Oli Kessler on January 30, 2004 at 04:57 AM MST #
Posted by Matt Raible on January 30, 2004 at 09:02 AM MST #
<script type="text/javascript">
var table = document.getElementById("itemsList");
var rows = table.getElementsByTagName("tr");
for (i=0; i < rows.length; i++) {
rows[i].onclick = function() { this.className='selectedRow' };
}
</script>
My table is part of an JSP include file that i Include into my main document this way:
<jsp:include page="Itemslist.jsp">
<jsp:param name="drilldownLinkEnabled" value="on"/>
</jsp:include>
Posted by Knut Erik Ballestad on March 15, 2004 at 04:27 PM MST #
<script type="text/javascript">
var table = document.getElementById("templatesList");
var rows = table.getElementsByTagName("tr");
for (i=0; i < rows.length; i++) {
rows[i].onclick = function() { this.className='selectedRow' };
}
</script>
My table is part of an JSP include file that i Include into my main document this way:
<jsp:include page="/list/Templates.jsp">
<jsp:param name="drilldownLinkEnabled" value="on"/>
</jsp:include>
Posted by Unknown on March 15, 2004 at 04:30 PM MST #
Posted by dries on June 03, 2004 at 03:42 AM MDT #
Posted by Jari Pakarinen on October 06, 2004 at 07:40 AM MDT #
Posted by Jari Pakarinen on October 06, 2004 at 08:27 AM MDT #
Posted by Andy on October 31, 2004 at 08:18 AM MST #
Posted by sam on November 05, 2004 at 08:01 PM MST #
Posted by 80.227.112.86 on April 26, 2005 at 08:59 AM MDT #
Don't know if this is still up-to-date (last posts are quite old), but anyway it could help (like it helped me :-) ).
There's a small problem in this script : it looses the odd / even classes when moving the cursor over rows (the rows have no classes once you moused over them)...
I've had to change it slighly to the following :
<code> </code>
Will try the links right now (tr onclicks)...
Thanks for the useful tips !
Cheers
Remi
Posted by Remi VANKEISBELCK on May 14, 2005 at 05:09 PM MDT #
Posted by Sandip Prashar on July 03, 2005 at 06:48 PM MDT #
Posted by scndsky on May 30, 2006 at 07:25 AM MDT #
Posted by Juan on June 07, 2006 at 05:58 PM MDT #
Posted by hemsie on July 19, 2006 at 04:29 AM MDT #
Posted by jojo rico on July 12, 2007 at 01:16 AM MDT #
Posted by jojo rico on July 12, 2007 at 01:16 AM MDT #
Posted by jojo rico on July 12, 2007 at 01:17 AM MDT #
Posted by jawad richa on July 12, 2007 at 01:18 AM MDT #
Posted by shakun on June 02, 2008 at 01:27 AM MDT #
Posted by shakun on June 02, 2008 at 01:28 AM MDT #
Posted by Marta on July 30, 2009 at 10:29 AM MDT #