W
Wim Roffal
Is it possible to use javascript to change the name of a field in a form?
Thanks,
Wim
Thanks,
Wim
Wim said:I did some experiments (in IE 5.5) and they give a rather dubious result.
Say I have the form MyForm and the inputfield MyInput.
Now I can change the name of the field. For example by saying
MyForm.MyInput.name = 'NewName';
When I submit the form the field will indeed have the new name. So far so
good. However, when I try to change the value of the field with
MyForm.NewName.value = 'something';
I have a problem. This will not work. But when I use the old name it will
work. The same thing applies when I use getElementsByName().
RIck Measham said:AFAIK:
When you talk about a form element as MyForm.MyInput you're talking about
the id, not the name. However if you've not set an id, the browser will
assume you want to use the name attribute. As you've seen, you can change
the name, but you cannot change the id. You've seen that submitting gets
the new name, so it's just in the page-level javascript that you need to
always refer to the element by its id.
Cheers!
Rick
Wim said:Is it possible to use javascript to change the name of a field in a form?
Thanks,
Wim
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.