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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vincentshiu
    New Member
    • Dec 2007
    • 2

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

    I need to dynamic create input element in some cases, and I use javascript to do that, like the following code:
    Code:
    ....
    var inputElement = document.createElement("input");
    this.inputElement.name= "fieldName";
    this.inputElement.type = "text";
    this.inputElement.value = "somevalue";
    ....
    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
    Code:
    function create()
    {
    	alert("abc:" + document.forms[0]['abc'].value );
    	document.forms[0]['abc'].setAttribute("name", "def");
    	alert("def:" + document.forms[0]['def'] );
    }
    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
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    hi ...

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

    kind regards

    Comment

    • vincentshiu
      New Member
      • Dec 2007
      • 2

      #3
      Thanks a lot. you really do me a big favor~~

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

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

        kind regards

        Comment

        Working...