Jump to content

Sorting A List


Vegdawg

Recommended Posts

All,I would like to add a sort function to our web page that currently has a list of our publications, is it possible to add a sort function via javascript to sort the <li> by author or date. What would I need to do to the list items to enable a sort to proceed? I am not all that familiar with Java so the easier the solution the better for me. For an example of the list style I am referring to see: http://www.plantmineralnutrition.net/publicationsleon.htm I will add all the publications to a large list that I would like to be sortable if possible. Any help anyone could offer would be greatly appreciated. Thank you

Link to comment
Share on other sites

so is this stuff coming from a database? You could do it on the server side, and then just include the code that will give the data <li> styling. If it's not from a database, you would probably have to do something where you create a string of each publication's text, checking the first letter of each and sorting like that. (is this alphabetical, btw?) A quicksort would probably help you out. Or maybe something with XML where you have all your publications in one giant file that can be updated as you add/remove titles, and then parse the XML in Javascript on the fly based on what sorting you need (name, date, author, etc).

Link to comment
Share on other sites

This is not a simple problem with a simple solution. Not understanding javascript very well makes it a lot harder. The fact that your list is made with incorrect HTML makes it harder still.If you even want to begin with this, please learn how to format a list correctly. Here's a hint: a list is surrounded by <ul> or <ol> tags. Another hint: A <p> element cannot come between two <li> elements. Nothing but empty space can come between <li> elements. Do not use empty <p> elements to create empty space. It "works" now, but it could lead to unpredictable results.It would also be helpful if your <ul> element has an id attribute. That will make it possible to get a programming reference to the list.

Link to comment
Share on other sites

The Scientist: The list is not from a database I created a list, and added the .pdf stored on a server. I am not sure how to proceed with your xml suggestion but I will surely research that method.Deirdre's Dad: Thank you for the hints to correct my HTML, I will make the proper changes, and add an <id> to the <ul> element I appreciate all your help, chances are I will be back with follow up questions, I appreciate you taking the time to look at my problem...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...