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
- Clear cookie example
- JavaScript getElementById innerHTML
- JavaScript getElementById Style
- Javascript Examples
- JavaScript add row dynamically to table
- New Page 1
- JavaScript Change link
- JavaScript Checkbox getElementById
- javascript clear textarea
- JavaScript Clock Timer
- JavaScript Cookies
- JavaScript Date Difference
- JavaScript duplicate string
- JavaScript Email Validation
- javascript focus input
- JavaScript get excel file data
- JavaScript getAttribute Href
- JavaScript getAttribute Style
- JavaScript getElementById div
- JavaScript getElementById Iframe
- JavaScript getElementById select
- JavaScript Hide Button
- JavaScript Hide Div
- JavaScript hide image
- JavaScript Hide Table Column
- JavaScript Hide Table Rows
- JavaScript Key Event
- JavaScript link
- JavaScript method location
- JavaScript move div
- JavaScript move file
- JavaScript move image
- JavaScript Navigate Back
- JavaScript navigate to page
- JavaScript Navigate to URL
- JavaScript indexOf substring
- JavaScript onkeypress event
- JavaScript Open file
- JavaScript Open link in new window
- JavaScript Open Modal Window


