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 08:46 AM MDT #
Posted by Matt Raible on April 23, 2003 at 10:41 AM MDT #
Posted by Benjamin Simpson on October 28, 2003 at 08: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 10:57 AM MST #
Posted by Matt Raible on January 30, 2004 at 03:02 PM 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 10: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 10:30 PM MST #
Posted by dries on June 03, 2004 at 09:42 AM MDT #
Posted by Jari Pakarinen on October 06, 2004 at 01:40 PM MDT #
Posted by Jari Pakarinen on October 06, 2004 at 02:27 PM MDT #
Posted by Andy on October 31, 2004 at 02:18 PM MST #
Posted by sam on November 06, 2004 at 02:01 AM MST #
Posted by 80.227.112.86 on April 26, 2005 at 02:59 PM 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 11:09 PM MDT #
Posted by Sandip Prashar on July 04, 2005 at 12:48 AM MDT #
Posted by scndsky on May 30, 2006 at 01:25 PM MDT #
Posted by Juan on June 07, 2006 at 11:58 PM MDT #
Posted by hemsie on July 19, 2006 at 10:29 AM MDT #
Posted by jojo rico on July 12, 2007 at 07:16 AM MDT #
Posted by jojo rico on July 12, 2007 at 07:16 AM MDT #
Posted by jojo rico on July 12, 2007 at 07:17 AM MDT #
Posted by jawad richa on July 12, 2007 at 07:18 AM MDT #
Posted by shakun on June 02, 2008 at 07:27 AM MDT #
Posted by shakun on June 02, 2008 at 07:28 AM MDT #
Posted by Marta on July 30, 2009 at 04:29 PM MDT #