dans.blog


The miscellaneous ramblings and thoughts of Dan G. Switzer, II

Adding Dynamic Input Elements In IE Fails To Update Element's Array...

If you've ever used the createElement to dynamically add form elements to a page, you may have run into this problem before. You're working on a form and need to add some dynamic checkbox elements to the DOM on-the-fly. The code works great in Firefox, but in IE the fields are only displayed—they're not getting added to the named element's field (document.formName.fieldName) array.

In order to resolve this problem, you need to add a little DOM hack for Internet Explorer. When you invoke the createElement() method you must specify the name of the tag in the string:

var oField = document.createElement("<input name=\"isCheckboxField\" />");

more…