Connecting Tech Pros Worldwide Forums | Help | Site Map

How to create input element with name or change an input element's name?

Newbie
 
Join Date: Dec 2007
Posts: 2
#1: Dec 12 '07
I need to dynamic create input element in some cases, and I use javascript to do that, like the following code:
Expand|Select|Wrap|Line Numbers
  1. ....
  2. var inputElement = document.createElement("input");
  3. this.inputElement.name= "fieldName";
  4. this.inputElement.type = "text";
  5. this.inputElement.value = "somevalue";
  6. ....
  7.  
and in some other place, I need to use JavaScript to access the value,
like :
document.forms[0]['fieldName'].value

The code works fine in FireFox,
but in IE(6), I found that the name of the inputElement is gone.
So I wrote some other script to change input element's name,
It still not work( but works in FireFox).
I have a input element in form, and use a button to trigger the following function
Expand|Select|Wrap|Line Numbers
  1. function create()
  2. {
  3.     alert("abc:" + document.forms[0]['abc'].value );
  4.     document.forms[0]['abc'].setAttribute("name", "def");
  5.     alert("def:" + document.forms[0]['def'] );
  6. }
  7.  
in FireFox, the name is changed, but in IE, the name is not changed, and 'def' is not exist in the form.

Are there any one know what's going on?

gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,136
#2: Dec 12 '07

re: How to create input element with name or change an input element's name?


hi ...

have a look at the links in this post ... it covers exactly your problem ;)

kind regards
Newbie
 
Join Date: Dec 2007
Posts: 2
#3: Dec 13 '07

re: How to create input element with name or change an input element's name?


Thanks a lot. you really do me a big favor~~
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,136
#4: Dec 13 '07

re: How to create input element with name or change an input element's name?


no problem ... post back to the forum in case you have more questions :)

kind regards
Reply


Similar JavaScript / Ajax / DHTML bytes