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

307
Views
Javascript redirect function is not redirecting
function myFunction() {
  location.replace("https://www.w3schools.com")
}

in the script tag

  <button onclick='myFunction()'>Submit</button>

in the html

Any idea why this very basic command doesn't work?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

check this example: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_redirect_webpage

If your button is inside the form then need to specify as type of button

<form>
 <button onclick="myFunction()" type="button">Replace document</button>
</form

about 4 years ago · Santiago Trujillo Report

0

I tested your code and it works fine.. Try clearing your cache inspect and right click on reload choose clear cache.

Did u link your script file ?

<script src="script.js"></script>
about 4 years ago · Santiago Trujillo 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!