Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, you can place the <code>&lt;input type="file"&gt;</code> outside your HTML form, and then use the <code>onChange</code> event to fill an <code>&lt;input type="hidden"&gt;</code> within the form that gets posted:</p> <pre><code>&lt;input type="file" onchange="document.getElementById('hidden_file').value = this.value;" /&gt; &lt;form method="POST"&gt; &lt;input type="hidden" id="hidden_file" value="" /&gt; &lt;input type="submit" /&gt; &lt;/form&gt; </code></pre> <p>However in modern browsers, you will only be able to access the file name, and not the full path. You may want to check the following Stack Overflow posts for further information on this topic:</p> <ul> <li><a href="https://stackoverflow.com/questions/1676035/cant-get-the-complete-address-while-uploading-a-file">Can’t get the complete address while uploading a file</a></li> <li><a href="https://stackoverflow.com/questions/81180/how-to-get-the-file-path-from-html-input-form-in-firefox-3">How to get the file path from HTML input form in Firefox 3</a></li> </ul> <hr> <p><strong>UPDATE:</strong></p> <p>The original question made me think that you only needed to copy the "file name" to another HTML form, and not the whole <code>&lt;input type="file"&gt;</code> representation.</p> <p>Further to the update, I assume you meant something like this:</p> <pre><code>&lt;input type="file" onchange="document.getElementById('hidden_file').value = this.value;" /&gt; &lt;form method="POST"&gt; &lt;input type="file" id="hidden_file" value="" /&gt; &lt;input type="submit" /&gt; &lt;/form&gt; </code></pre> <p>Unfortunately the above does not work. Firefox will return <code>"Security error code: 1000"</code> if you try the above example.</p> <p>As for some workarounds, you may want to the check <a href="https://stackoverflow.com/users/19068/david-dorward">David Dorward</a>'s suggestions:</p> <ul> <li><a href="https://stackoverflow.com/questions/2220120/html-copy-form-fields-to-another-form-including-file-input-field/2221786#2221786">Using <code>cloneNode</code></a></li> <li><a href="https://stackoverflow.com/questions/2220120/html-copy-form-fields-to-another-form-including-file-input-field/2221756#2221756">Moving the input field with <code>appendChild</code> before submitting the form</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload