I have created a HTML5 Form and now on the click of the submit button I call a JavaScript function. I want to determine which page to display next (“success.html” or “error.html”) based on the value returned from the function (true or false respectively). How do I achieve that…. I have written following code for this …
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://code.jquery.com/jquery-1.6.2.js"></script>
<script>
function submitData(){
var browserName = navigator.appName;
if (browserName=="Microsoft Internet Explorer")
{
var emailId = document.getElementById("emailId").value;
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(emailId.value)) {
alert('Please provide a valid email address');
emailId.focus;
return false;
}
}else{
alert("This is not IE. You are lucky. Your browser is : "+browserName);
}
return true;
}
</script>
</head>
<body>
<form id ="myForm" action ="success.html" method="get" onsubmit="return submitData()" onerror="error.html">
<h1 style="color: darkgoldenrod"> Registration Form </h1>
Name :
<input id ="nameId" type="text" autofocus="true" placeholder="Enter your Name " required="true"/> <br/>
email ID :
<input id ="emailId" type="email"/>
Age :
<input type="number" min="18" max="70" step="1" value="26">
<input type="submit" name="submit" />
</form>
</body>
</html>
Thanks, as you might guess I am new in HTML and JavaScript.. So any help will be really appreciated…
Appending the following code inside the
<script>, aftersubmitDatashould do the trick.