Forum Moderators: open
I'm really stuck with an array I'm trying to convert.
The array looks like:
liOrder=new Array('li0', 'li1', 'li2', 'li3');
The order of the list items on my page can change. Therefor the order of the liOrder array can also change.
For example: liOrder=('li2', 'li1', 'li0', 'li3');
I need to first check if the order of the array has changed (if the list items have been dragged and re-ordered by the user).
<script language="JavaScript" type="text/javascript">
if(liOrder!="0,1,2,3"){// if the list has been re-ordered I need a way to figure out
// what the order is on page load and somehow, re-order the
// list items to the liOrder arrays new value.}
</script>
I don't know howto do this! I'm hoping someone here does :)
I should state, I've written the javascript to create and read a cookie to save the order of the list items. I just can't figure out how to change the list structure to reflect the order.
Thanks for reading. Sorry about the lengthy post!
[pre]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>List equal to Array</title>
<script type="text/javascript">
window.onload = function(){
var testOrder = "'li2','li1','li0','li3'";
var arr = eval("[" + testOrder + "]");
var lista = document.getElementById('lista');
lista.innerHTML = "<li>" + arr.join("</li><li>") + "</li>";
}
</script>
</head>
<body>
<ul id="lista">
<li>li1</li>
<li>li2</li>
<li>li3</li>
<li>li4</li>
</ul>
</body>
</html>[/pre]
Andrew
[edited by: Little_G at 6:56 pm (utc) on Sep. 7, 2007]