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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.