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

156
Visualizações
Set different url in the action(form) based on input

I want the action of the form to have different urls based on the input that is passed to it, the problem is that passing the correct urls to the action does not work as it should.

Next I will put some images to be more descriptive

This is the form

<div id="search">
    <form id="formID" action="javascript:;" onsubmit="chgAction()" autocomplete="off">
        <input id="inputID" type="text" placeholder="Search.." autofocus="autofocus">
    </form>
</div>

Here I take the value of the input and I nest it to reddit and in the end I pass it as action and it doesn't work

var text = document.getElementById("inputID").value
document.getElementById("formID").action = "https://www.reddit.com/search/?q=" + text;

The result is this enter image description here

The url is like 'bugged', but if i use POST in method (form) I get the correct url but say this.

enter image description here

But If i click on the url then enter if it works. enter image description here

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

0

I believe it is because the GET request is sending out the request before you can obtain the value of the input. I would suggest using e.preventDefault() instead, then create your URL based on the input, then send a fetch() request.

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