Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-23-2010, 07:07 PM   PM User | #1
maxetime
New to the CF scene

 
Join Date: Aug 2010
Location: Montreal, Canada
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
maxetime is an unknown quantity at this point
Reordering text input values

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
maxetime is offline   Reply With Quote
Reply

Bookmarks

Tags
input, javascript, order, reordering

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:20 PM.


Advertisement
Log in to turn off these ads.