Jump to content

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

}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.