Hi,

I'm currently programming a menu editing script and I'm trying to reorder value of text input on change.

What I'm trying to do is when I change the value of a text box it reorders the others.

EX
Start 1 2 3 4 5
Change 3->1
End 2 3 1 4 5

Here is what I've manage to do, it works only when the number is bigger.

Javascript function
Code:
function changeOrder(current)
{
	var num_name = current.name.split("_",2);
	var id = num_name[0]+"_"+num_name[1]+"_number";
	var maxorder = document.getElementById(id).value;
	var currentmax = current.name.substr((current.name.length-1),1)
	if(currentmax <= maxorder && current.value > 0)
	{
		var start = (currentmax > current.value ? 1 : currentmax);
		for(var i=start;i<maxorder;i++)
		{
			var k = parseInt(i)+1;
			x = document.getElementsByName(num_name[0]+"_"+num_name[1]+"_order_"+k);
			x[0].value = i;
			x[0].name = x[0].name.substr(0,(x[0].name.length-1))+i;
		}
		current.name = current.name.substr(0,(current.name.length-1))+current.value;
	}
}
HTML input
Code:
<input type="text" style="width: 20px;" onchange="changeOrder(this);" value="1" name="other_title_order_1">
Thanks for any advices you may have

Maxetime