Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change names of formfields with js

Status
Not open for further replies.

BayK

Programmer
Aug 6, 2004
4
AT
Hi

I do have a problem changing the name of fields using js....

I'm sure there's an easy solution but i can't figure it out ^^

I just want to change the names of formfields (inputs or textareas)

Code:
document.getElementsByName('myName')[0].name = 'test';

this expression should set the name of the first Element named myName to test.

i wanted to include this feature into this function

Code:
	function setName(name)
	{
		var Elemente = new Array();

		for(i=0; ;i++)
		{
			node = document.getElementsByName(name + i);
			if(node[0] == null && document.getElementsByName(name + (i+1))[0] == null)
				break;
			for(j=0; j<node.length; j++)
				Elemente.push(node[j]);
		}

		for(i=0; i<Elemente.length; i++)
			Elemente[i].name = name + i;
	}
 
With regards to IE running "JScript", you cannot change the name entirely:

MSDN said:
Microsoft JScript allows the name to be changed at run time. This does not cause the name in the programming model to change in the collection of elements, but it does change the name used for submitting elements.

See here for more details:


Hope this helps,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top