SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Afraid I can't do that Dave Hal9k's Avatar
    Join Date
    Mar 2004
    Location
    East Anglia, England.
    Posts
    640
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Variable File uploads

    Hey there,

    The user needs to upload files, but the number of files they need to upload is variable.

    I've got something like this:

    Code:
    function another_file() { 
    document.getElementById('files').innerHTML += '<input type="file" class="fileinput" name="pictures[]" />';
    }
    But everytime I click on the link that calls that function, it erases the previous input's state.

    I'm after something like GMail's attachments interface.

    Thanks for reading.

  2. #2
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    try like this:
    HTML Code:
    <script type="text/javascript">
    function file_input()  
    {  form = document.getElementById('activity'); 
        inp = document.createElement('input');      
        inp.setAttribute('type','file');      
        inp.setAttribute('name','pictures[]');      
        // inp.setAttribute('value','123');      
        form.appendChild(inp);  
    }  
    </script>
    
    
    <form id="activity">
    <input type="button" value="add field" onclick="file_input()">
    </form>
    Last edited by VMashch&Co; Jul 27, 2006 at 13:56.

  3. #3
    Afraid I can't do that Dave Hal9k's Avatar
    Join Date
    Mar 2004
    Location
    East Anglia, England.
    Posts
    640
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool, neato VMashch&Co!

    I'll hook it up to the PHP backend and see how it goes.

    Cheers


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •