Jump to content

[SOLVED] file input box help


jake2891

Recommended Posts

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;

}

Link to comment
https://forums.phpfreaks.com/topic/170106-solved-file-input-box-help/
Share on other sites

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/

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);

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.