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
Share on other sites

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

}

Link to comment
Share on other sites

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.