Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2008
    Posts
    48
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Array in alphabetical via div ID

    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
    Code:
    <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>

  • #2
    New to the CF scene
    Join Date
    May 2009
    Location
    Bs. As., Argentina
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi.

    Try this script.

    Code:
    <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!!!

  • #3
    New Coder
    Join Date
    Oct 2008
    Posts
    48
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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]

    Code:
    <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?
    Last edited by Bambam007; 05-23-2009 at 03:30 AM. Reason: clear wording

  • #4
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    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.

  • Users who have thanked venegal for this post:

    Bambam007 (05-25-2009)

  • #5
    New Coder
    Join Date
    Oct 2008
    Posts
    48
    Thanks
    10
    Thanked 0 Times in 0 Posts
    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.
    Last edited by Bambam007; 05-25-2009 at 02:25 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •