The code works as expected in FF and Opera. However in IE7, it will only create one additional field.
Can anyone explain why IE7 refuses to create any more fields?
Expand|Select|Wrap|Line Numbers
- <script type="text/javascript" language="javascript">
- //initialises the container
- function init() {
- container = document.getElementById('fieldset_images');
- }
- //checks if ANY childnode is empty
- function empty(){
- var children = container.childNodes;
- var count = children.length;
- for(var i =0; i <count; i++) {
- var childval = children[i].value;
- if (childval == "") return(true);
- }
- return(false);
- }
- //makes the field
- function createField(){
- //checks if any fields are empty
- if (empty()) return;
- input = document.createElement("input");
- input.setAttribute("type", "file");
- input.setAttribute("name", 'file[]');
- input.setAttribute("onchange", 'createField();');
- container.appendChild(input);
- }
- window.onload = init;
- </script>
- <fieldset id="fieldset_images"><input type="file" name="file[]" onchange="createField();" /></fieldset>