Vegdawg Posted March 9, 2010 Share Posted March 9, 2010 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 More sharing options...
thescientist Posted March 9, 2010 Share Posted March 9, 2010 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 More sharing options...
jeffman Posted March 9, 2010 Share Posted March 9, 2010 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 More sharing options...
Vegdawg Posted March 10, 2010 Author Share Posted March 10, 2010 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 More sharing options...
thescientist Posted March 10, 2010 Share Posted March 10, 2010 just check out the XML tutorial, see if it could help you out Link to comment Share on other sites More sharing options...
justsomeguy Posted March 10, 2010 Share Posted March 10, 2010 You may want to consider listing your publications in a table, there are plenty of scripts available to dynamically sort tables. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.