Click to See Complete Forum and Search --> : column index


saju_m
08-19-2003, 12:04 PM
how to get the column index by clicking on the column of a table. is there something like rowindex?

thank you

Khalid Ali
08-19-2003, 01:23 PM
pretty much all html elements are drawn in collections on the a page.Which means you can retrieve all of the

tables in the document
all of th rows in each table
and all of the td(cells) in each row

The rest is all dependant on what you are trying to do.And how will the logical flow of your program intend to get the row index?
using an event that triggers to get the row index or how??

give some more details I may be able to help you.

AdamBrill
08-19-2003, 01:38 PM
Here is an example of how to get the innerHTML of the row that you clicked:<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function clicked(event){
if(event.target){
element = event.target.parentNode;
}else{
element = event.srcElement.parentElement;
}
alert(element.innerHTML);
}
</script>
</head>
<body onclick="clicked(event);">
<table border=1>
<tr>
<td>
1
</td>
<td>
2
</td>
</tr>
</table>
</body>
</html>You should be able to do whatever you wanted to do with that...

Fang
08-19-2003, 02:37 PM
This wil give your column number:

<html>
<head>
<title>Column number</title>
<script type="text/javascript">
function Column(e) {
var ColNum=1;
if(navigator.userAgent.indexOf("MSIE")!=-1) {
if(event.srcElement.tagName=="TD") {
ColNum+=event.srcElement.cellIndex;
}
}
else {
if (e.target == "[object HTMLTableCellElement]") {
ColNum+=e.target.cellIndex;
}
}
alert("Column="+ColNum);
}
</script>
</head>
<body onclick="Column(event);">
<table id="table1" border="1" cellpadding="5" cellspacing="0" summary="">
<tr><td>1a</td><td>2a</td><td>3a</td></tr>
<tr><td>1b</td><td>2b</td><td>3b</td></tr>
</table>
</body>
</html>

EshQ
07-02-2010, 07:29 AM
omg i was looking for this all over!!
anyway.. i manged to get this working with simple table..
but it wont get the correct column index when i'm using it on my gridView (which is scrollable btw)... is there a way to make work for gridViews too?