Question : Javascript to get <TD> inner text in MSIE, FF and Chrome

Hello,

I've got a table where the first column is a checkbox inside a <SPAN> in a <TD> in <TR>. If this checkbox is checked, I want to get the value of another <TD> in the same <TR>. I wrote the javascript code below which gets a list of values of all checked lines in my table. The problem is that it works in MSIE (8) only. In FF and Chrome, I get a list of "undefined" strings. How can I make my code work in all of these browser? Thanks.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
function GetSelectedJobIds(caller) {
  result = '';
  if (caller == null || !caller.hasChildNodes)
     return false;
  // Loop over all the elements in the form, looking for 
  // checkboxes to read.
  nodes = caller.form.elements;
  if (nodes == null)
     return false;
  for (i = 0; i < nodes.length; i++) {
      if (nodes[i].type == "checkbox") {
         if (nodes[i].id.indexOf("chkSelectJob") != -1) {
             if (nodes[i].checked || nodes[i].checked=='checked') {
                 result = result + ',' + nodes[i].parentNode.parentNode.parentNode.childNodes[2].innerText;
              }
              nodes[i].checked = false;
          }
          else if (nodes[i].id.indexOf("chkSelectAllJobs") != -1) {
           nodes[i].checked = false;
           }
        } 
    }

Answer : Javascript to get <TD> inner text in MSIE, FF and Chrome

Problem is in line:

result = result + ',' + nodes[i].parentNode.parentNode.parentNode.childNodes[2].innerText;

Child nodes for IE and FF are indexed in different way.
Try using independent collections
if nodes[i].parentNode.parentNode.parentNode is a row
try:
nodes[i].parentNode.parentNode.parentNode.cells[2].innerText

rgds
rumi


Random Solutions  
 
programming4us programming4us