dynamic file input controls

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J.R

    dynamic file input controls

    Greetings,

    I'm adding dynamically created input type='file' controls via JavaScript.
    However when I try to access they do not seem to be returned in the form
    collection. Any ideas?

    Thanks, John.


  • VK

    #2
    Re: dynamic file input controls

    You cannot set/access file properties from JavaScript : the access is locked
    for security reasons.


    J.R <someone@somewh ere.com> wrote in message
    news:Y7abb.4118 $I36.3840@pd7tw 3no...[color=blue]
    > Greetings,
    >
    > I'm adding dynamically created input type='file' controls via JavaScript.
    > However when I try to access they do not seem to be returned in the form
    > collection. Any ideas?
    >
    > Thanks, John.
    >
    >[/color]


    Comment

    • Ivo

      #3
      Re: dynamic file input controls

      "J.R" <someone@somewh ere.com> wrote in message
      news:Y7abb.4118 $I36.3840@pd7tw 3no...[color=blue]
      > Greetings,
      >
      > I'm adding dynamically created input type='file' controls via JavaScript.
      > However when I try to access they do not seem to be returned in the form
      > collection. Any ideas?
      > Thanks, John.[/color]

      Are you sure they have unique names, or if not, unique indeces in an array?
      Here is what I use, more or less directly copied from the page so it is not
      tailored to the question:

      <script type=text/javascript>
      function add(n){
      curdiv=document .activeElement. previousSibling ;
      newdiv=curdiv.c loneNode(true);
      curdiv.insertAd jacentElement(" afterEnd",newdi v);
      }
      </script>

      <form method=post enctype="multip art/form-data" action="/script.htm">
      <input type=hidden name=MAX_FILE_S IZE value=3000000>
      <div>File: <input type=file name=userfile[]></div>
      <input class=button type=button value="Add" onclick=add(thi s) ><br>
      <input class=button type=submit value=" Upload ">
      </form>


      There are several forms on this page, each with their own "Add" button, and
      in the case of the upload form with the <input type=file>,
      activeElement.p reviousSibling (not sure if this is IE only) is the div
      containing both the input and its label. Note the input name is a member of
      an array because of the square brackets. This ensures the server script that
      receives the form submission will see all inputs, regardless of how many
      times I clicked "Add"!

      HTH
      Ivo


      Comment

      Working...