Javascript code for sorting a listbox:
<hr>
function SortList()
{
var last = document.getElementById("listBox1").options.length - 2;
var isChanged = 1;
var TempText,TempVal;
while ( last >= 0 && isChanged )
{
isChanged = 0;
for ( var k = 0; k <= last; k++ )
if ( document.getElementById("listBox1")(k).text.toUpperCase() > document.getElementById("listBox1")(k+1).text.toUpperCase() )
{
TempText = document.getElementById("listBox1")(k).text;
TempVal = document.getElementById("listBox1")(k).value;
document.getElementById("listBox1")(k).text = document.getElementById("listBox1")(k+1).text;
document.getElementById("listBox1")(k).value = document.getElementById("listBox1")(k+1).value;
document.getElementById("listBox1")(k+1).text = TempText;
document.getElementById("listBox1")(k+1).value = TempVal;
isChanged = 1;
}
last--;
}
return;
}
Bharathi Kambhampati
No comments:
Post a Comment