0

I have table in the jsp which is dynamically populated. I used same id for all the table rows.

In the javascript I want to retreive all the table row elements whose id is "resultRow". and getElementsByName("resultRow") in js gives empty htmlcollection in IE10

Is there any other way to get the tablerows of matched id

Any help is greatly appreciated

`here is my code snippet

In JSP:
<table id="subSecondTable" cellpadding="0" cellspacing="0">
   <c:set var="loopCount" value="0" />
   <c:forEach var="vinList" items="${requestScope.vehicleDetailsPO}">
     <tr id="resultRow" height="10" class="handCursor"
       onclick="rowColorChange('<c:out value="${loopCount}"/>','<c:out value="${vinList.vin}"/>');">

In js:
function rowColorChange(rowNumber,vin){ 
    var rows=document.getElementsByName("resultRow");   
    var columns;
    rowHighlighted=rowNumber;       
    for(i=0;i<rows.length;i++){
        if (i==rowNumber){      
            rows[rowNumber].style.backgroundColor="blue";
            //change the text color for the highlighted row 
            columns = rows[rowNumber].cells
            for(j=0;j<columns.length;j++){
                columns[j].style.color = "white";
            }
            //change the text color for the highlighted row
            var previousRowint = parseInt(previousRow);                 
            if (previousRow != rowNumber)
            {               
                columns = rows[previousRowint].cells
                for(j=0;j<columns.length;j++){
                    columns[j].style.color = "black";
                }
            }               
            previousRow=rowNumber; 
            if(vin==''){             
                vin = rows[parseInt(rowHighlighted)].cells[3].innerText;
            }
            document.getElementById("txtCopyVin").value=vin;
            document.getElementById("txtCopyVin").select();
        }else{      
            rows[i].style.backgroundColor="white";                       
        }
    }
    if(window.event!=null){
        rows[rowNumber].cells(window.event.srcElement.cellIndex).focus();
    }
}`     
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Harish
  • 425
  • 3
  • 7
  • 19

3 Answers3

1

I've just confirmed with my own testing that this is a change that Microsoft seems to have made in IE10 to make it compatible with every other browser on the market. In every other browser, ID and name are different things. But until IE 10, Microsoft chose to do things differently, which caused lots of incompatibilities, as described here. This change fixed my code written for chrome, but seems to have broken code written for IE.

If you instruct your users to turn on "compatibility mode", it should work as before, but that's probably not a good long term solution.

The good news is if you go through and fix this issue in your code by making id's refer to id's and names refer to names, your site will then be compatible with other browsers besides IE.

Looking at your code, it seems you want to replace id="resultRow" with name="resultRow"

jsarma
  • 1,344
  • 11
  • 19
0

This behavior is by design.
name and id are two different things.

In addition, ids must be unique; your HTML is invalid.

You should use class instead, and call getElementsByClassName().

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

Since when were name and id equal? To give an example, how many people have the name John Smith (besides the Doctor)? In spite of that, they all have unique IDs. The same applies to your HTML.

Use <tr name="resultRow"...>, then you can access getElementsByName('resultRow')

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592