jake2891 Posted August 13, 2009 Share Posted August 13, 2009 hey guys i have a file input box on my form and next to it i have a link that saying + attahment that calls a javascript function that fills a div with a new file input box so the user can add as many file input boxes as they please. the problem is that if they have browsed a file then add another file input box the file that was in the first get wiped out. any ideas on how to solve this problem? here a sample of my code <div id="attFile"> <input name="uploadedfile[]" type="file" value="<?php echo ''; ?>"/> <a href="javascript:_add_more();" title="Add more">+ attachment</a> the javascript function function _add_more() { var txt = "<br><input type=\"file\" name=\"uploadedfile[]\">"; document.getElementById("attFile").innerHTML += txt; } Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 13, 2009 Share Posted August 13, 2009 any ideas on how to solve this problem? Yep. If you are going to use a HTML form, you must create all the file input fields first because only the browser can put values into the HTML file input fields or you can use a FLASH form to do what you want - http://swfupload.org/ Quote Link to comment Share on other sites More sharing options...
jake2891 Posted August 13, 2009 Author Share Posted August 13, 2009 thanks for your help. i managed to find a way around the problem by using the dom. here is what i did incase you ever come across something similar function _add_more() { var new_upload = document.createElement( 'input' ); new_upload.type = 'file'; new_upload.name = 'uploadedfile[]'; document.getElementById("attFile").appendChild(new_upload); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.