jump_ace
12-08-2011, 10:34 PM
Hi,
I've built a sorting table for what will (hopefully) be a leaderboard for Forza 4. I have the table sorted properly and my current script (within the table) adds up all three T columns and brings the total to 72.001 as expected, woot!
Where I'm stuck is converting the 72.001 to 1 minute 12.001 seconds (1:12.001) and I need to have it include the thousandths since the game gives that information. Once I get the JS going for the top row I can copy down :)
Any advice on converting this is greatly appreciated and I Bolded the JS I'm referring to:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Forza Motorsport 4 FRS Leaderboard</title>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="sortable.js"></script>
<style>
table {
text-align: left;
font-size: 12px;
font-family: verdana;
background: #c0c0c0;
}
table thead {
cursor: pointer;
}
table thead tr,
table tfoot tr {
background: #c0c0c0;
}
table tbody tr {
background: #f0f0f0;
}
td, th {
border: 1px solid white;
}
</style>
</head>
<body>
<table cellspacing="3" cellpadding="4" class="" id="myTable">
<thead>
<tr>
<th class="c1">DRIVER</th>
<th class="c2">1</th>
<th class="c2">2</th>
<th class="c2">3</th>
<th class="c6">TOTAL</th>
<th class="c5">DIVISION</th>
<th class="c7">CONTROLLER</th>
</tr>
</thead>
<tbody>
<tr id="SubTable1" class="r1">
<td class="c1">Driver Name 1</td>
<td class="c2">12.000</td>
<td class="c2">24.000</td>
<td class="c2">36.001</td>
<script language="javascript" type="text/javascript">
var tds = document.getElementById('SubTable1').getElementsByTagName('td');
var totalTime = 0.000;
for(var i = 0; i < tds.length; i ++) {
if(tds[i].className == 'c2') {
totalTime += isNaN(tds[i].innerHTML) ? 0 : parseFloat(tds[i].innerHTML);
}
}
document.getElementById('SubTable1').innerHTML += totalTime;
</script>
<td class="c5">1</td>
<td class="c7">Wheel</td>
</tr>
<tr class="r2">
<td class="c1">Driver Name 2</th>
<td class="c2">12.100</th>
<td class="c3">24.100</th>
<td class="c4">36.100</th>
<td class="c6">00.000</th>
<td class="c5">2</th>
<td class="c7">Gamepad</th>
</tr>
<tr class="r2">
<td class="c1">Driver Name 3</th>
<td class="c2">12.200</th>
<td class="c3">24.200</th>
<td class="c4">36.200</th>
<td class="c6">00.000</th>
<td class="c5">3</th>
<td class="c7">Wheel</th>
</tr>
<tr class="r2">
<td class="c1">Driver Name 4</th>
<td class="c2">12.300</th>
<td class="c3">24.300</th>
<td class="c4">36.300</th>
<td class="c6">00.000</th>
<td class="c5">4</th>
<td class="c7">Gamepad</th>
</tr>
<tr class="r2">
<td class="c1">Driver Name 5</th>
<td class="c2">12.400</th>
<td class="c3">24.400</th>
<td class="c4">36.400</th>
<td class="c6">00.000</th>
<td class="c5">5</th>
<td class="c7">Wheel</th>
</tr>
</tbody>
</table>
<script type="text/javascript">
var t = new SortableTable(document.getElementById('myTable'), 100);
</script>
</body>
</html>
Oh, and any help on centering the result in the cell (72.001) would be excellent too, thank you.
Jerome
I've built a sorting table for what will (hopefully) be a leaderboard for Forza 4. I have the table sorted properly and my current script (within the table) adds up all three T columns and brings the total to 72.001 as expected, woot!
Where I'm stuck is converting the 72.001 to 1 minute 12.001 seconds (1:12.001) and I need to have it include the thousandths since the game gives that information. Once I get the JS going for the top row I can copy down :)
Any advice on converting this is greatly appreciated and I Bolded the JS I'm referring to:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Forza Motorsport 4 FRS Leaderboard</title>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="sortable.js"></script>
<style>
table {
text-align: left;
font-size: 12px;
font-family: verdana;
background: #c0c0c0;
}
table thead {
cursor: pointer;
}
table thead tr,
table tfoot tr {
background: #c0c0c0;
}
table tbody tr {
background: #f0f0f0;
}
td, th {
border: 1px solid white;
}
</style>
</head>
<body>
<table cellspacing="3" cellpadding="4" class="" id="myTable">
<thead>
<tr>
<th class="c1">DRIVER</th>
<th class="c2">1</th>
<th class="c2">2</th>
<th class="c2">3</th>
<th class="c6">TOTAL</th>
<th class="c5">DIVISION</th>
<th class="c7">CONTROLLER</th>
</tr>
</thead>
<tbody>
<tr id="SubTable1" class="r1">
<td class="c1">Driver Name 1</td>
<td class="c2">12.000</td>
<td class="c2">24.000</td>
<td class="c2">36.001</td>
<script language="javascript" type="text/javascript">
var tds = document.getElementById('SubTable1').getElementsByTagName('td');
var totalTime = 0.000;
for(var i = 0; i < tds.length; i ++) {
if(tds[i].className == 'c2') {
totalTime += isNaN(tds[i].innerHTML) ? 0 : parseFloat(tds[i].innerHTML);
}
}
document.getElementById('SubTable1').innerHTML += totalTime;
</script>
<td class="c5">1</td>
<td class="c7">Wheel</td>
</tr>
<tr class="r2">
<td class="c1">Driver Name 2</th>
<td class="c2">12.100</th>
<td class="c3">24.100</th>
<td class="c4">36.100</th>
<td class="c6">00.000</th>
<td class="c5">2</th>
<td class="c7">Gamepad</th>
</tr>
<tr class="r2">
<td class="c1">Driver Name 3</th>
<td class="c2">12.200</th>
<td class="c3">24.200</th>
<td class="c4">36.200</th>
<td class="c6">00.000</th>
<td class="c5">3</th>
<td class="c7">Wheel</th>
</tr>
<tr class="r2">
<td class="c1">Driver Name 4</th>
<td class="c2">12.300</th>
<td class="c3">24.300</th>
<td class="c4">36.300</th>
<td class="c6">00.000</th>
<td class="c5">4</th>
<td class="c7">Gamepad</th>
</tr>
<tr class="r2">
<td class="c1">Driver Name 5</th>
<td class="c2">12.400</th>
<td class="c3">24.400</th>
<td class="c4">36.400</th>
<td class="c6">00.000</th>
<td class="c5">5</th>
<td class="c7">Wheel</th>
</tr>
</tbody>
</table>
<script type="text/javascript">
var t = new SortableTable(document.getElementById('myTable'), 100);
</script>
</body>
</html>
Oh, and any help on centering the result in the cell (72.001) would be excellent too, thank you.
Jerome