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

148
Visualizações
Get current value of input HTML JS

I have an html page that requires getting the value of an input when a button is pressed so it can be used as a variable in a link. For example, my website would detect "word" being written in the input and would redirect to the link "google.com/word" when the button is clicked. Thanks for any help in advance!

HTML Code:

<td><input value="Input text Here..."></input></td>
<td><a href='https://example.com/test/VALUEFROMINPUTHERE'><button id="click">Click this Button</button></a></td>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

There is not way to get input value only using HTML... give your button an onclick attribute:

<td>
  <a href='https://example.com/test/VALUEFROMINPUTHERE'>
    <button id="click" onclick="click()">Click this Button</button>
  </a>
</td>

and your input an ID:

<td>
  <input value="Input text Here..." id="input">
</td>

and add JS:

function click() {
  let val = document.getElementById("input").value
  window.location.href = "https://www.google.com/search?q=" + val
}

All I'm doing here is geting the input's value, and changing the window's href to the wanted word, also making sure the word is being searched in google by adding the "https://www.google.com/search?q=" before adding the value of the input.

about 4 years ago · Juan Pablo Isaza Relatório

0

In this code, when the a tag is clicked, it triggers a JS function that grabs the value of the input with the id "value" and opens thee link with by concatenating it's value to the end of the URL with the window.open() function.

<input type="text" placeholder="Enter Text" id="value" />
<a href="#" onClick="openLink()">Click Me</a>
<script>
function openLink() {
  let value = document.getElementById("value").value
  window.open(`https://www.example.com/${value}`)
}
</script>
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