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

123
Views
how to redirect a html page in javascript

I'm working on the Javascript page for my registration form. I simply just can't figure out how to make the page redirect to another page if everything's filled out.

document.getElementById("check").onclick = function() {
  let allAreFilled = true;
  document.getElementById("myForm").querySelectorAll("[required]").forEach(function(i) {
    if (!allAreFilled) return;
    if (!i.value) allAreFilled = false;
    if (i.type === "radio") {
      let radioValueCheck = false;
      document.getElementById("myForm").querySelectorAll(`[name=${i.name}]`).forEach(function(r) {
        if (r.checked) radioValueCheck = true;
      })
      allAreFilled = radioValueCheck;
    }
  })
  if (!allAreFilled) {
    alert('Fill all the fields');
  }
  else {
    window.location.replace("http://www.w3schools.com");
  }
}; 
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

I'm giving my sample script for the same possible problem I hope this helps

HTML

<pre>
<!DOCTYPE HTML>
<html>
<body>
<p id=P >Fill in all checkboxes</p>
    <form>
        <input type=radio />
        <label>Check 1</label>
        
        <input type=radio />
        <label>Check 2</label>
        
        <input type=radio />
        <label>Check 3</label>
    </form>
</body>
</html>
</pre>

JavaScript

window.onload = () => 
{

var radio = document.querySelectorAll('[type=radio]'),
p = document.getElementById("P");
 
radio.forEach( 
    function(i)
    {
        i.onchange = () => 
        {
            var checked = document.querySelectorAll("[type=radio]:checked"),
                leftover = radio.length - checked.length;
            p.innerHTML = "leftover checkbox " + leftover;
            
            if(radio.length == checked.length)
            {
                alert("All checked");
                window.location.href = "https://ilhamb.com/";
            }
            
        }
    }
)
}
about 4 years ago · Juan Pablo Isaza Report

0

Use window.location.href to redirect within the same tab /window or use window.open() to redirect in a new tab /window.

As Quentin pointed out, you are already using an appropriate way to redirect. May I suggest opening the console and checking if there are console errors ? Also make sure that your program actually reaches the redirect by using a browser breakpoint or console logs.

about 4 years ago · Juan Pablo Isaza Report

0

This code

window.location = "w3schools.com"

Or

window.location.href = "w3schools.com"

should do it

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!