Click here to Skip to main content
16,004,574 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Actually I already wrote the sort by option in my javascript. It is not working in Interent Explorer 9 version but it's working all other browsers and IE 11 as well. Is there any tags need to give for that?

XML
<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=Windows-1252">
<script type="text/javascript">
var people, asc1 = 1, asc2 = 1;
window.onload = function() {
people = document.getElementById("people");
}

function sort_table(tbody, col, asc) {
var rows = tbody.rows, rlen = rows.length, arr = new Array(), i, j, cells, clen;
// fill the array with values from the table
for (i = 0; i < rlen; i++) {
cells = rows[i].cells;
clen = cells.length;
arr[i] = new Array();
for (j = 0; j < clen; j++) {
arr[i][j] = cells[j].innerHTML;
}
}
// sort the array by the specified column number (col) and order (asc)
arr.sort(function(a, b) {
return (a[col] == b[col]) ? 0
: ((a[col] > b[col]) ? asc : -1 * asc);
});
// replace existing rows with new rows created from the sorted array
for (k = 0; k < rlen; k++) {
rows[k].innerHTML = "<td class='tdclass'>"
+ arr[k].join("</td><td class='tdclass'>") + "</td>";
}

}

function selectRadio() {
var radioValue="";
if (document.getElementById('radioId1').checked) {
sort_table(people, 2, asc1); asc1 *= -1; asc2 = 1;
} else if (document.getElementById('radioId2').checked) {
sort_table(people, 2, asc2); asc2 *= -1; asc1 = 1;
}


}
</script>

<body>
<br/>
<br/>
<table>
<tr>
<td class="tdheadclass"><input type="button" value="Main Menu" /><span class="tab"></span></td>
<td class="tdheadclass"><input type="button" value="New Search" /><span class="tab"></span></td>
<td class="tdheadclass">
<input type="radio" id="radioId1" name="radioId" value="Id" checked>Id
<input type="radio" id="radioId2" name="radioId" value="Email Id">Email Id<span class="tabLess"></span>
<input type="button" value="Sort by" />
</td>
<td class="tdheadclass"><input type="button" value="Save As" /><span class="tab"></span></td>
Posted
Updated 28-Jul-15 8:56am
v2
Comments
Sergey Alexandrovich Kryukov 28-Jul-15 14:07pm    
Sorry, we don't have your code to give any advice.
—SA

1 solution

looks like you already know the answer to
Quote:
How do I write sort by option in JavaScript?
Since you said
Quote:
it's working all other browsers and IE 11 as well.
May be you should provide your code ask how to make it work with IR9.
 
Share this answer
 
Comments
Member 11869547 28-Jul-15 14:50pm    
Here is the code...
<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=Windows-1252">
<script type="text/javascript">
var people, asc1 = 1, asc2 = 1;
window.onload = function() {
people = document.getElementById("people");
}

function sort_table(tbody, col, asc) {
var rows = tbody.rows, rlen = rows.length, arr = new Array(), i, j, cells, clen;
// fill the array with values from the table
for (i = 0; i < rlen; i++) {
cells = rows[i].cells;
clen = cells.length;
arr[i] = new Array();
for (j = 0; j < clen; j++) {
arr[i][j] = cells[j].innerHTML;
}
}
// sort the array by the specified column number (col) and order (asc)
arr.sort(function(a, b) {
return (a[col] == b[col]) ? 0
: ((a[col] > b[col]) ? asc : -1 * asc);
});
// replace existing rows with new rows created from the sorted array
for (k = 0; k < rlen; k++) {
rows[k].innerHTML = "<td class='tdclass'>"
+ arr[k].join("</td><td class='tdclass'>") + "</td>";
}

}

function selectRadio() {
var radioValue="";
if (document.getElementById('radioId1').checked) {
sort_table(people, 2, asc1); asc1 *= -1; asc2 = 1;
} else if (document.getElementById('radioId2').checked) {
sort_table(people, 2, asc2); asc2 *= -1; asc1 = 1;
}


}
</script>

<body>
<br/>
<br/>
<table>
<tr>
<td class="tdheadclass"><input type="button" value="Main Menu" /><span class="tab"></span></td>
<td class="tdheadclass"><input type="button" value="New Search" /><span class="tab"></span></td>
<td class="tdheadclass">
<input type="radio" id="radioId1" name="radioId" value="Id" checked>Id      
<input type="radio" id="radioId2" name="radioId" value="Email Id">Email Id<span class="tabLess"></span>
<input type="button" value="Sort by" />
</td>
<td class="tdheadclass"><input type="button" value="Save As" /><span class="tab"></span></td>
Patrice T 28-Jul-15 14:58pm    
I have put your code in the question, it is the place you should have put it from beginning.
You can "improve your question if the end of the code is missing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900