JavaScript navigate to page
In this section, you will learn how to navigate from one page to another using JavaScript. For this purpose, we have created two html pages navigatePage.html and page.html. Here we are going to navigate from navigatePage.html to page.html. In navigatePage.html, we have created a button and used the href property of the location object with the onClick event which allows this page to navigate to page.html where we have created a simple form.
Here is the code of navigatePage.html:
| <html> <h2>Navigate Page</h2> <input type="button" value="go to next page" onclick="location.href='page.html' "> </html> |
Here is the code of page.html:
| <html> <h3>Form</h3> <script> function valid(){ if (document.form.name.value == ""){ alert ( "Please enter Name." ); return false; } if (document.form.address.value == ""){ alert ( "Please enter Address." ); return false; } alert("Thanks for filling the form."); return true; } </script> <form name="form" method="post" onSubmit="valid();"> <table> <tr><td>Enter Name:</td><td><input type="text" name="name"></td></tr> <tr><td>Enter Address:</td><td><input type="text" name="address"></td></tr> <tr><td><input type="submit" value="Submit"></td></tr> </table> </form> </html> |
Output will be displayed as:
On clicking the button, you will navigate to next page:

Tutorials
- Java 26 (JDK 26) Features with examples
- Top 10 Reasons to Learn Java in 2026
- JDK 26 Tutorial
- Java Certification Roadmap 2026: Which Oracle Certs Matter
- Install JDK 26: A Complete Beginner's Guide (2026)
- What Is Java? A Complete, Up-to-Date Guide for 2026
- Java 26 HTTP3 tutorial - HTTP 3 support in JDK 26 - How to use HTTP/3 in Java 26 application?
- JDK 28 Preview: Value Objects, Shenandoah GC & JSON API
- Java Tutorials


