...

View Full Version : Array in alphabetical via div ID



Bambam007
05-22-2009, 11:39 AM
Hi All,

I have an Unordered List, each List Item has a div nested inside with an ID.

I am constantly adding to this list, it has to be in alphabetical order, so its kind of a pain to update. I thought I could make things a little easier by using a javascript array to sort it out via the nested div ID. But I can't figure it out, please help...

I don't want to click, i just want the page to load already in place.

here is and example of my list

<li><div id="chimney"><a href="index.php?page=001"></a></div></li>
<li><div id="zendo"><a href="index.php?page=002"></a></div></li>
<li><div id="peaches"><a href="index.php?page=003"></a></div></li>

hshadow
05-22-2009, 09:45 PM
Hi.

Try this script.


<script type="text/javascript">
var words = new Array();
words[0]="Mia";
words[1]="Laura";
words[2]="Ann";

words.sort() //Orders Asc

//Print
for($i= 0; $i<=2; $i++)
{
document.write($i+1+" : "+words[$i]+"<br />");
}


words.reverse() //Orders Desc

//Print
for($i= 0; $i<=2; $i++)
{
document.write($i+1+" : "+words[$i]+"<br />");
}

</script>

See ya!!!

Bambam007
05-23-2009, 04:27 AM
That's cool, except my list is not just words
I need to order lines that look like this...
[Hopefully using the ID 'peaches' in this case]


<li><div id="peaches"><a href="index.php?page=003"></a></div></li>

or at least...
use those words, as you have listed, as the ID's and have it swap out!

But how?

venegal
05-23-2009, 01:20 PM
Would be easier to generate those <li>s in the right order server side instead of generating them in the wrong order and then ordering them client side.

Bambam007
05-25-2009, 03:18 AM
Oh, you mean via a php-mySQL database?
Ok, you are probably right, I was barking up the wrong tree, hehe.
I'll put my very new database hat on.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum