Adding form fields dynamicly

Discussion in 'Javascript' started by emperor-laban@home.se, Jan 21, 2005.

  1. Guest

    How can I add more <input type="file" /> -fields by the click of a
    button? The idea is that the clients should be able to upload a number
    of files from the same form, but I shouldn't need to know how many
    fields they need to begin with. Would be good to have an option to
    remove fields as well.
     
    , Jan 21, 2005
    #1
    1. Advertising

  2. wrote:

    > How can I add more <input type="file" /> -fields by the click of a
    > button? The idea is that the clients should be able to upload a number
    > of files from the same form, but I shouldn't need to know how many
    > fields they need to begin with. Would be good to have an option to
    > remove fields as well.


    You can create elements with the factory method createElement of the
    document and then insert it as needed in your document with e.g.
    appendChild called on the element you want to insert the input it, for
    instance the form element object or one of its descendants:
    var input;
    if (document.createElement && (input =
    document.createElement('input'))) {
    input.type = 'file';
    input.name = 'file1';
    input.id = 'file1';
    form.appendChild(input);
    }

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 21, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?WWFuaXI=?=

    Dynamicly get the form name at server

    =?Utf-8?B?WWFuaXI=?=, Apr 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    287
    bruce barker
    Apr 19, 2004
  2. DaWoE

    Creating a form dynamicly

    DaWoE, Sep 1, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    591
    DaWoE
    Sep 1, 2004
  3. GS
    Replies:
    4
    Views:
    2,766
    Teemu Keiski
    Feb 15, 2006
  4. kyle.tk
    Replies:
    2
    Views:
    285
    Robert Kern
    Aug 31, 2005
  5. Owen Wong
    Replies:
    0
    Views:
    331
    Owen Wong
    Sep 12, 2006
Loading...

Share This Page