dreamwest Posted January 17, 2009 Share Posted January 17, 2009 Is there a way to order a list by name?? Bannana Orange Apple Mango Once ordered by name it will be: Apple Bannana Mango Orange Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted January 17, 2009 Share Posted January 17, 2009 are these items in a list such as a <ul> <li>Bannana</li> <li>Orange</li> <li>Apple</li> <li>Mango</li> </ul> if so you could create a function that loops throught the elements and rebuilds the list Quote Link to comment Share on other sites More sharing options...
dreamwest Posted January 17, 2009 Author Share Posted January 17, 2009 are these items in a list such as a <ul> <li>Bannana</li> <li>Orange</li> <li>Apple</li> <li>Mango</li> </ul> if so you could create a function that loops throught the elements and rebuilds the list Yes taht would work but i know nothing about javascript, i know php,mysql and html. I cant use php because im using smarty templates, but the template will accept javascript programming Can someone give me an example of how this would work..Thanks Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted January 17, 2009 Share Posted January 17, 2009 I cant use php because im using smarty templates, but the template will accept javascript programming Can someone give me an example of how this would work..Thanks hmmm I never used smarty but I do think that using smarty doesnt mean you cant use php. It's probably better to use php to order an array. If you do really want to do it with Javascript then here is a start for you list element with id html <ul id="list"> <li>Bannana</li> <li>Orange</li> <li>Apple</li> <li>Mango</li> </ul> javascript <script type="text/javascript"> //the <ul> element var list=document.getElementById('list'); //all items in an array var elements=list.children </script> you will have to place this script after the ul html otherwise it wont see it. That or you need a domready event Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 17, 2009 Share Posted January 17, 2009 I cant use php because im using smarty templates, but the template will accept javascript programming Sort the list in PHP _before_ assigning it to smarty variable. Quote Link to comment Share on other sites More sharing options...
dreamwest Posted January 17, 2009 Author Share Posted January 17, 2009 I cant use php because im using smarty templates, but the template will accept javascript programming Sort the list in PHP _before_ assigning it to smarty variable. Zend encrypted they are Quote Link to comment Share on other sites More sharing options...
dreamwest Posted January 17, 2009 Author Share Posted January 17, 2009 Tried it but it Didnt work: <ul id="list"> <script type="text/javascript"> //the <ul> element var list=document.getElementById('list'); //all items in an array var elements=list.a,b,c,d </script> <li>A</li> <li>E</li> <li>D</li> <li>C</li> <li>B</li> </ul> Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted January 17, 2009 Share Posted January 17, 2009 It had errors in it and where did list.a,b,c,d come from but as i said before its only a start it's not a complete working script. the elements variable is now an array you just have to sort it. and what did you mean with Zend encrypted? it's still the better option <ul id="list"> <li>A</li> <li>E</li> <li>D</li> <li>C</li> <li>B</li> </ul> <script type="text/javascript"> //the <ul> element var list=document.getElementById('list'); //all items in an array var elements=list.getElementsByTagName('li'); //examle of how to loop through the elements for(var i=0;i<elements.length;i++){ document.write(elements[i].innerHTML+"<br/>"); } </script> Quote Link to comment Share on other sites More sharing options...
dreamwest Posted January 17, 2009 Author Share Posted January 17, 2009 im getting no where with this....keeps throwing errors.....i might just do it through phpmyadmin Thanks anyhows Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.