mounika
mounika

Reputation: 35

How to move a page from one to another in HTML after Validation

Here is my code

index.html


<html>
<head></head>
<body>
<div id="top"> New Record </div><br>
<form name="myForm"  onsubmit="return validateForm()" method="post">
 <h5>Record name: <input type="text" name="name" id="name"></h5>
 <div >
 <h5>Submitted Date <input id="sub" type="text" name="submited date" ></h5>
</div>
<div>
<h5>Started Date <input id="strtd" type="text" name="started date" ></h5>
</div>
 <div>
<h5> Record Type <select name="Record Type" id="options">
 <option value="Document">Documents</option>
 <option value="Pictures">Pictures</option>
<option value="Sounds">Sounds</option>
</select></h5>

</div>
 <div align="center">
<input id="submit" type="submit" value="Create">
<button id="cancel" type="button" onclick="ClearFields();">Reset</button>
</div>
</form>
</body>
</html>

and script is here

  $(function(){
 var pickerOpts = {
  appendText: "",
  defaultDate: "+5",
  showOtherMonths: true,
  dateFormat: "dd/mm/yy",
 };  

  $("#strtd").datepicker({
   minDate: 0
  });

  $("#sub").datepicker({ 
  maxDate: new Date, 
 minDate: new Date(2007, 6, 12)
  });

  $('#strtd').focus(function() {
 this.blur();
  });
 $('#sub').focus(function() {
  this.blur();
  });

   });

  //form validation

  function validateForm() {
var x = document.forms["myForm"]["name"].value;
var y= document.forms["myForm"]["strtd"].value;
var z= document.forms["myForm"]["sub"].value;
if (x==null || x=="") {
    alert("First name must be filled out");
    return false;
 }

else if (y==null || y=="") {
    alert("Started Date must be filled out");
    return false;
  }

 else if (z==null || z=="") {
    alert("Submitted Date must be filled out");
    return false;
  }
  else {

  alert("New Reocrd Created");
 window.location.href = "http://www.google.com";
  }
 }



function ClearFields() {
  document.getElementById("name").value="";
  document.getElementById("strtd").value="";
  document.getElementById("sub").value=""
}

In the above scripting code I have taken the example "window.location.href = "http://www.google.com"; just for checking and my requirement is to move the page to another html page

eg:details.html

on clicking on create button. Iam getting alert as "New Record Created" but not moving to next page. Hope anyone of you helps :) Thanks in advance

Upvotes: 0

Views: 6425

Answers (1)

Arijit Mukherjee
Arijit Mukherjee

Reputation: 3875

window.location.href is not a method, it's a property that will tell you the current URL location of the browser. Setting the property to something different will redirect the page.

window.open() is a method that you can pass a URL to that you want to open in a new window. For example:

window.location.href example:

window.location.href = 'http://www.google.com'; //Will take you to Google. window.open() example:

window.open('http://www.google.com'); //This will open Google in a new window.

Source : SO Answer by James Hill

In case you want to open a local html page use:

window.location('fullpath');

Upvotes: 1

Related Questions