Re: Dynamically-generated hidden input fields
Philip Thompson <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.dom |
|---|---|
| Message-ID | <[email protected]> |
On Mar 3, 2008, at 3:34 PM, Philip Thompson wrote:
> Hi there. I am dynamically creating hidden input fields in JS. As
> usual, IE is giving me problems. I can do this in FF and it works
> fine, but as soon as I attempt to access this in IE, it explodes:
>
> <js>
> var form = document.alertForm;
> var count = form.length;
>
> for (var i=0; i<count; i++) {
> // This works fine in IE - all fields print
> alert(form.elements[i].name+': '+form.elements[i].value);
> }
>
> // This does NOT work in IE, but does in FF
> // 'call_method' is a hidden input that I create dynamically
> alert(form.call_method.name+':: '+form.call_method.value);
> </js>
>
> Note, in the for() loop, 'call_method' displays its name and value
> just fine. But when I attempt to access it directly
> (form.call_method), it doesn't work in IE - I get an "Error on page"
> with the error being "Object expected", code 0. Anyone know of a
> work-around/solution for this?
>
> Thanks,
> ~Philip
I found the issue. Apparently IE doesn't set the name of a form field
when using createElement. I found this solution in this thread:
http://codingforums.com/showthread.php?t=132080
View the 3rd comment (from A1ien51). He provides a link that has a
workaround for it:
http://www.pascarello.com/examples/createElement.html
View the source and see how he deals with it. I plugged it into my
code and it works perfectly. Hope this helps someone else having the
same problem...
Thanks,
~Philip