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

218
Visualizações
How do I set the URL of a hyperlink to a js variable?

I need help with setting urls to JS variables,

<input id="urlbox"><a href="main.htm" target=main id=gourl><button>Go</button></a>
<script>
  var urlgo = document.getElementById('gourl');
  var seturl = document.getElementById('urlbox').value;
  setInterval(function() {
  urlgo.setAttribute('href', seturl);
}, 300);
</script>

It doesn't work in any internet browser I tested it in, how do I get it to work?
The behavior I expected is that every 0.3 seconds, the url of the go button is set to the value of the text box, but nothing happens when i use it, does anyone know how to make it work?
If it helps, I don't get an error, but the url just gets set to blank no matter what I enter

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

0

Place the

var urlgo = document.getElementById('gourl');
var seturl = document.getElementById('urlbox').value;

inside the the setInterval.

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