Forum Moderators: open
<html>
<head>
<script>
function addtoarray(evt)
{if (evt) {evt=(evt)?evt:((event)?event:null);
elem=(evt.target)?evt.target:evt.srcElement;
elem.style.visibility='hidden';}
fileupl=document.getElementById('addingfiles');
fileupl.innerHTML("<br><input type='file'><input type='button' style='width:25px' onclick=addtoarray(event) value='+'>";
}
</script>
</head>
<body>
<div id="addingfiles">
</div>
<script>addtoarray();</script>
</body>
</html>
Remember that it rewrites the HTML. Perhaps that should include the values, but it doesn't. File inputs do behave in a special way because of security concerns. For instance, you can't set a value on a file input via script.
Either way, you didn't need the event querying part of the function. Using 'this' in the event handler for the + button will achieve the desired effect.
This should work:
[pre]
<html>
<head>
<script>
function addtoarray(elem)
{
elem.style.visibility='hidden';
var parent = elem.parentNode;
parent.appendChild( document.createElement('<input type="file">'));
parent.appendChild( document.createElement(
'<input type="button" style="width:25px" onclick="addtoarray(this)" value="+">'
));
}
</script>
</head>
<body>
<div id="addingfiles" style="width:300px;"><!--width is for wrapping-->
<input type="file">
<input type="button" style="width:25px" onclick="addtoarray(this)" value="+">
</div>
</body>
</html>
[/pre]