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

142
Visualizações
Passing a single variable to an href in html

          <div class="d-flex align-items-center">
                      <div class="container-fluid" style="float: right;">
                        <form class="d-flex">
                          <input type="text" placeholder="Search" aria-label="Search" style="width: 400px;" id="searchTerm" name="searchTerm" ></input>
                          <script>
                            var inputVal = document.getElementById("searchTerm").value;
                          </script>
                          <a href="/articles/search" class="btn btn-success" onclick="location.href=this.href+'?term='+inputVal;" style="width: 100px;">Search</a>
                
              </form>
            </div>
          </div>

I am trying to pass the value from the input to a new page and then retrieve that variable on the next page. I am not sure that I am passing it correctly and am not sure how to retrieve it once it is sent to the next page.

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

0

You can use the "change" event listener:

let inputElement = document.querySelector("#searchTerm");

inputElement.addEventListener("change", ()=>{
    let inputVal = document.getElementById("searchTerm").value;
    let anchorElement = document.querySelector(".d-flex > a");
    anchorElement.href = `/articles/search/${inputVal}`;
});
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