Home Javascript Javascriptexamples JavaScript navigate to page
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

JavaScript navigate to page

Advertisement
This page discusses - JavaScript navigate to page

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:

Download Source Code:

        

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Related Tutorials

Ask Questions?    Discuss: JavaScript navigate to page  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Kalpana
June 21, 2012
Navigating Page

Thanks...it helped me a lot:)
DMCA.com