Adding form fields dynamicly

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • emperor-laban@home.se

    Adding form fields dynamicly

    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.

  • Martin Honnen

    #2
    Re: Adding form fields dynamicly



    emperor-laban@home.se wrote:
    [color=blue]
    > 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.[/color]

    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.creat eElement && (input =
    document.create Element('input' ))) {
    input.type = 'file';
    input.name = 'file1';
    input.id = 'file1';
    form.appendChil d(input);
    }

    --

    Martin Honnen

    Comment

    Working...