Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
How to fill a input type="file" through only Javascript?

I'm trying to fill a form and submit it using only JS.

For instance, in this page :

<form>
    <input id="yourname" type="text"></input><br/>
    <input id="yourfile" type="file"></input><br/>
    <input type="submit"></input><br/>
</form>

I'm trying to use something like this to submit the form :

document.getElementById('yourname').value = 'Paul';
document.getElementById('yourfile').value = 'c:\users\admin\desktop\myfile.jpg';
document.forms[0].submit();

I know the second line of the script above will throw an exception. Instead, I could click on the input:

document.getElementById('myfile').value = 'Paul';

But this will open a window to select the file, but I can't fill this window using JS... can I?

Is there any workaround for this? Or is the only way to select a file in a web form manually?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

...i can't fill this window using JS... or can i ?

No, you are not able to fill that form through JavaScript.

If you could, it would allow websites to take files from your computer without your knowledge, which would be a huge security violation. That's why it makes a window open on your desktop: so that the user knows that the site is trying to download a file.

[Are there] any [workarounds] for this or the only way to select a file in a web form is manually?

No, there are no workarounds for this feature.

As I said above, it would be a major security issue if you could do this, so the only way to get a file from a user is to use the popup window.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda