huolto
asked on
Javascript: Get selected cell.cellIndex from a table in iframe
I have a iframe with a dynamically generated table. What I need to get is the cellindex value of the selected cell when a centain button is pressed. I need it so that i can define the row and the column where the selected cell is. The button is outside the iframe and i can't use onclick or any other event parameters in the iframe.
The selected cell which cellindex value i need has cursor in it, because it's in designmode. The cell in the table might have dublicate values, so i can't determine the cell by it's contents.
Is there an easy way to get the selected cells values?
The selected cell which cellindex value i need has cursor in it, because it's in designmode. The cell in the table might have dublicate values, so i can't determine the cell by it's contents.
Is there an easy way to get the selected cells values?
You need to set the variables interactivly in the iframe.
In the head of the iframe page:
<script type="text/javascript">
<!--
therow='';
thecell='';
//-->
</script>
Then in the cells add this event:
onClick="therow=this.paren tNode.rowI ndex; thecell=this.cellIndex;">
Then in the event handler for the button on the main page you can reference the last value set:
localrow=top.frames[0].the row;
localcell=top.frames[0].th ecell;
Cd&
In the head of the iframe page:
<script type="text/javascript">
<!--
therow='';
thecell='';
//-->
</script>
Then in the cells add this event:
onClick="therow=this.paren
Then in the event handler for the button on the main page you can reference the last value set:
localrow=top.frames[0].the
localcell=top.frames[0].th
Cd&
ASKER
Hi all.
Dfu, The frame is in design mode (just like in a wysiwyg editor), so that is why it can be edited.
The solution for adding id's to table doesn't work, because the idea was to have the table free of extra html.
Coboldinosaur, that is why I can't add onclick event or the variables inside the iframe.
Is it possible to get the rowIndex and cellindex from the iframe by clicking the button, with a command similar to your cell calling event.
Let's say the iframe is named Iframe.
<input type="button" value="get cellIndex" onclick="getCell(Iframe.th is.cellInd ex)">
function getCell(cellIndex){
var sel = Iframe.document.selection;
var theFrame = sel.createRange();
alert(theFrame.text);
}
gives out the text value of the cell, but i can't get the cellIndex value, which I need to check the row and the column.
Dfu, The frame is in design mode (just like in a wysiwyg editor), so that is why it can be edited.
The solution for adding id's to table doesn't work, because the idea was to have the table free of extra html.
Coboldinosaur, that is why I can't add onclick event or the variables inside the iframe.
Is it possible to get the rowIndex and cellindex from the iframe by clicking the button, with a command similar to your cell calling event.
Let's say the iframe is named Iframe.
<input type="button" value="get cellIndex" onclick="getCell(Iframe.th
function getCell(cellIndex){
var sel = Iframe.document.selection;
var theFrame = sel.createRange();
alert(theFrame.text);
}
gives out the text value of the cell, but i can't get the cellIndex value, which I need to check the row and the column.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The C grade without explanation is unacceptable. I am asking for a review.
Cd&
Cd&
If that is the case then you should be able to name the inputs (for example, txt_1_1) and be able to keep a page level variable that points to the input object wheneven one receives focus ... from there you can parse the id (or name) to find the row and column that it is in ...
HTH