Jump to content

odered list by name


dreamwest

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/141195-odered-list-by-name/#findComment-739008
Share on other sites

 

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

 

Link to comment
https://forums.phpfreaks.com/topic/141195-odered-list-by-name/#findComment-739017
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/141195-odered-list-by-name/#findComment-739092
Share on other sites

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>  

Link to comment
https://forums.phpfreaks.com/topic/141195-odered-list-by-name/#findComment-739113
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.