Get value of a loop generated table cell via onClick
Hello,
I am trying to get the value of a table cell that is generated by a php loop. The purpose is so eventually I can click a row out of a list and have it take me to a form view of the list item that is clicked. I've searched and searched for the last few days for something with no luck. I run across a lot of hits that tell me I need to have an id for everysingle thing I click on but there has to be a better way.
function as best I could make
Code:
function test() {
var elTableRow = document.getElementById("tr");
var elTableCells = elTableRow.getElementsByTagName("gtrpart");
alert(elTableCells[0].innerText);
}
So then how would I call a specific row when I click it? lets say I set the whole table row to a unique value that it gets from the loop, how would I call that specific row from my function without having 1000+ functions?
function functionName(tid) { // tid is the variable that contains the ID of the cell calling the function..
var thisContent = document.getElementById(tid).firstChild;
alert(thisContent);
}
^_^
PS.. if you want CELL text, you don't put the ID on the TR, you put it on the TD.
var thisContent = document.getElementById(tid).firstChild;
No. A textNode is an Element/Object as well. Should be:
Code:
var thisContent=document.getElementById(tid).firstChild.nodeValue;
//or
var thisContent=document.getElementById(tid).firstChild.data;
//or
var thisContent=document.getElementById(tid).innerText||document.getElementById(tid).textContent; // IE||full DOM compliant browsers
But if the container element has no textNode - is empty - not even a blank space within (like <td></td>) all those will return "undefined".
? What he said what? I saw your code, and I have noticed that it is not correct. A textNode is an object, thus if you want to return its "stringed content" you must do it properly.
Bookmarks