Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!