R
rrowles2000
Hi,
I have four chuncks of html and I'm trying to sort them. see this
link. Basically the sort works for alphabetic sort but not for
numerics. Any ideas very welcome? I just can't see what I'm doing
wrong!!! Cheers
http://cricketclub.wherwell.net/bowling-averages-2007.htm
each chunk looks like this...
<div id="player_1" class="player">
<table>
<tr>
<td>1</td>
<td><div class="playerName" id="playerName_1">d</div></td>
<td><div class="overs" id="overs_1">10</div></td>
<td><div class="maidens" id="maidens_1">0</div></td>
<td><div class="runs" id="runs_1">50</div></td>
<td><div class="wickets" id="wickets_1">90</div></td>
<td>
<div class="averageRuns" id="averageRuns_1"></div>
<script language="javascript">
document.getElementById('averageRuns_1').innerHTML =
Math.round((parseInt(document.getElementById('runs_1').innerHTML) /
parseInt(document.getElementById('wickets_1').innerHTML))*100)/100;
</script>
</td>
</tr>
</table>
</div>
And the code is here.
<script language="javascript">
function quickSort(prefix,htmlItem,t)
{
var n =1;
while (n < getArrayLength(prefix))
{
var makeSwap = false;
if (t == 'c')
{
if((sv(prefix + n)) > (sv(prefix + (n+1))))
{makeSwap = true;}
}
if (t == 'l')
{
if(parseLong(sv(prefix + n)) > parseLong(sv(prefix + (n
+1))))
{makeSwap = true;}
}
if (t == 'i')
{
if(parseInt(sv(prefix + n)) > parseInt(sv(prefix + (n
+1))))
{makeSwap = true;}
}
if(makeSwap)
{
document.getElementById(prefix + n).style.background
= '#ccc';
document.getElementById(prefix + (n
+1)).style.background = '#ccc';
swapHTML(htmlItem+n, htmlItem+(n+1),n);
alert('Pause');
document.getElementById(prefix + n).style.background
= '#fff';
document.getElementById(prefix + (n
+1)).style.background = '#fff';
}
n++;
}
}
function swapHTML(a,b,f)
{
alert('a:'+a+' b:'+b+' n:'+f);
var aHTML = document.getElementById(a).innerHTML;
var bHTML = document.getElementById(b).innerHTML;
var cHTML = document.getElementById(b).innerHTML;
document.getElementById(b).innerHTML = aHTML.replace('_'+(f),'_'+(f
+1));
document.getElementById(a).innerHTML = cHTML.replace('_'+(f+1),'_'+
(f));
}
function getHTML(elementName)
{
return trim(document.getElementById(elementName).innerHTML);
}
function trim(str)
{
return ltrim(rtrim(str));
}
function sv(elementName)
{
return document.getElementById(elementName).innerHTML;
}
function getArrayLength(prefix)
{
var m=1;
var elementId = prefix + m;
while (idExists(elementId))
{
m++;
elementId = prefix + m;
}
return m-1;
}
function idExists(elementId)
{
if (document.getElementById(elementId) == null)
{return false;}
else
{return true;}
}
</script>
I have four chuncks of html and I'm trying to sort them. see this
link. Basically the sort works for alphabetic sort but not for
numerics. Any ideas very welcome? I just can't see what I'm doing
wrong!!! Cheers
http://cricketclub.wherwell.net/bowling-averages-2007.htm
each chunk looks like this...
<div id="player_1" class="player">
<table>
<tr>
<td>1</td>
<td><div class="playerName" id="playerName_1">d</div></td>
<td><div class="overs" id="overs_1">10</div></td>
<td><div class="maidens" id="maidens_1">0</div></td>
<td><div class="runs" id="runs_1">50</div></td>
<td><div class="wickets" id="wickets_1">90</div></td>
<td>
<div class="averageRuns" id="averageRuns_1"></div>
<script language="javascript">
document.getElementById('averageRuns_1').innerHTML =
Math.round((parseInt(document.getElementById('runs_1').innerHTML) /
parseInt(document.getElementById('wickets_1').innerHTML))*100)/100;
</script>
</td>
</tr>
</table>
</div>
And the code is here.
<script language="javascript">
function quickSort(prefix,htmlItem,t)
{
var n =1;
while (n < getArrayLength(prefix))
{
var makeSwap = false;
if (t == 'c')
{
if((sv(prefix + n)) > (sv(prefix + (n+1))))
{makeSwap = true;}
}
if (t == 'l')
{
if(parseLong(sv(prefix + n)) > parseLong(sv(prefix + (n
+1))))
{makeSwap = true;}
}
if (t == 'i')
{
if(parseInt(sv(prefix + n)) > parseInt(sv(prefix + (n
+1))))
{makeSwap = true;}
}
if(makeSwap)
{
document.getElementById(prefix + n).style.background
= '#ccc';
document.getElementById(prefix + (n
+1)).style.background = '#ccc';
swapHTML(htmlItem+n, htmlItem+(n+1),n);
alert('Pause');
document.getElementById(prefix + n).style.background
= '#fff';
document.getElementById(prefix + (n
+1)).style.background = '#fff';
}
n++;
}
}
function swapHTML(a,b,f)
{
alert('a:'+a+' b:'+b+' n:'+f);
var aHTML = document.getElementById(a).innerHTML;
var bHTML = document.getElementById(b).innerHTML;
var cHTML = document.getElementById(b).innerHTML;
document.getElementById(b).innerHTML = aHTML.replace('_'+(f),'_'+(f
+1));
document.getElementById(a).innerHTML = cHTML.replace('_'+(f+1),'_'+
(f));
}
function getHTML(elementName)
{
return trim(document.getElementById(elementName).innerHTML);
}
function trim(str)
{
return ltrim(rtrim(str));
}
function sv(elementName)
{
return document.getElementById(elementName).innerHTML;
}
function getArrayLength(prefix)
{
var m=1;
var elementId = prefix + m;
while (idExists(elementId))
{
m++;
elementId = prefix + m;
}
return m-1;
}
function idExists(elementId)
{
if (document.getElementById(elementId) == null)
{return false;}
else
{return true;}
}
</script>