Wim Roffal wrote:
> Is it possible to use javascript to change the name of a field in a form?
>
> Thanks,
> Wim
I'm not sure why you'd need to do such a thing. There are a myriad of other
alternative solutions that don't require the ability to change the name of
form element.
For example, if the name is one of a set of known values, then simply have a
hidden input for each known name and stick the value in the appropriate
input.
If there are many possible names, or the name is not known at the time the
form is loaded, then replace the concept of a named form element with two
elements, one containing the "name", one containing the "value". Once
submitted to the server, it can make the necessary connection:
<input type="hidden" name="elementName" value="defaultName" />
<input type="hidden" name="elementValue" value="defaultValue" />
Lastly, if you really need to do this (and I'm still not convinced there
isn't an alternative solution) then you could simply create the element on
the fly and name it whatever you want:
var elem = document.createElement("input");
elem.type = "hidden";
elem.name = "myInputName";
elem.id = "myInputId";
elem.value = "theValue";
document.forms['theForm'].appendChild(elem);
The code above will need to be protected against being run on browsers which
do not understand or implement document.createElement() and appendChild()
properly.
--
| Grant Wagner <>
* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
*
http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
*
http://www.mozilla.org/docs/web-deve...upgrade_2.html