andre72
asked on
Select Cells in a table on mouseover
Hi,
I'm looking for a way to select cells in a grid when when mouse is over it.
Eg.:
The user clicks on a cell and that is the start cell.
Now while mouse move the cells where the mouse is over will become hightlight and when the user clicks again the current cell will be the end cell.
I hope you can understand what I try to explain :-)
Any sample how this is possible?
Thanks
Andre
I'm looking for a way to select cells in a grid when when mouse is over it.
Eg.:
The user clicks on a cell and that is the start cell.
Now while mouse move the cells where the mouse is over will become hightlight and when the user clicks again the current cell will be the end cell.
I hope you can understand what I try to explain :-)
Any sample how this is possible?
Thanks
Andre
I think you are looking something like this. (attached)
I have modified the code of "jscheuer1" from "http://www.dynamicdrive.com/forums/archive/index.php/t-11390.html"
I have modified the code of "jscheuer1" from "http://www.dynamicdrive.com/forums/archive/index.php/t-11390.html"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title>Table Column Highlighting - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
#theT {
width:80%;
border-top:3px groove silver;
border-right:3px groove silver;
}
#theT td {
border-left:3px groove silver;
border-bottom:3px groove silver;
}
</style>
<script type="text/javascript">
/* Highlight Table Columns © John Davenport Scheuer
* As first seen in http://www.dynamicdrive.com/forums/
* This notice must remain for legal use */
var useHighlighting = false;
var i_start = 0;
var j_start = 0;
function toggleHighlighting(i, j){
if (useHighlighting)
useHighlighting = false;
else
{
clearHighlighting();
var tTab=document.getElementById('theT')
tTab.rows[i].cells[j].style.backgroundColor='yellow';
i_start = i;
j_start = j;
useHighlighting = true;
}
}
function hCol(i, j, clr){
if (useHighlighting){
var tTab=document.getElementById('theT')
for (var i_tem = i_start; i_tem <= i; i_tem++)
for (var j_tem = j_start; j_tem <= j; j_tem++)
tTab.rows[i_tem].cells[j_tem].style.backgroundColor=clr;
}
}
function eCol(){
var tTab=document.getElementById('theT')
for (var i_tem = 0; i_tem < tTab.rows.length; i_tem++)
for (var j_tem = 0; j_tem < tTab.rows[i_tem].cells.length; j_tem++){
tTab.rows[i_tem].cells[j_tem].onmouseover=new Function("hCol("+i_tem+", " + j_tem + ", 'yellow');");
tTab.rows[i_tem].cells[j_tem].onmouseout=new Function("hCol("+i_tem+", "+ j_tem + ", '');");
tTab.rows[i_tem].cells[j_tem].onclick=new Function("toggleHighlighting("+i_tem+", "+ j_tem + ");");
}
}
function clearHighlighting(){
var tTab=document.getElementById('theT')
for (var i_tem = 0; i_tem < tTab.rows.length; i_tem++)
for (var j_tem = 0; j_tem < tTab.rows[i_tem].cells.length; j_tem++)
tTab.rows[i_tem].cells[j_tem].style.backgroundColor='';
}
onload=eCol;
</script>
</head>
<body>
<table id="theT" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> </tr>
<tr> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> </tr>
<tr> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> </tr>
<tr> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> </tr>
<tr> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> </tr>
<tr> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> </tr>
<tr> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> </tr>
<tr> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> <td><br> </td> </tr>
</tbody>
</table>
<br>
<input type="button" value="clear highlighting" onClick="javascript:clearHighlighting()">
</body>
</html>
Table-Highlighting.html
ASKER
Yes siddagrl this is exact what I'm looking for.
But why does it only work in the # direction down and right?
After start selection mouse move to the left or up it does not select any more?
But why does it only work in the # direction down and right?
After start selection mouse move to the left or up it does not select any more?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your support!
Open in new window