Reputation: 9
Q1. How could I place a code that can redirect the page after the form submitted??
Q2. I am looking some article about return value
, anyone please recommend some good article for me.
<form method="post" name="formName">
<input type="text" value="Name" name="cName">
<br>
<input type="submit" onClick="return fValidator(this)">
</form>
<script language="javascript1.8.5" type="text/javascript">
function fValidator(){
var vName = document.formName.cName;
var nameReg = /^[a-zA-Z]+$/;
if (vName.value != ''){
if (vName.value.match(nameReg)){
alert("Your form is sumitted now!");
return true;
location.replace("http://www.w3schools.com");
} else{
alert("Alphabet only!");
return false;
}
} else{
alert("Fill the mandatory field!");
return false;
}
}
</script>
Upvotes: 0
Views: 258
Reputation: 34
Use "onsubmit".
Eg: <form onsubmit="myFunction()">
This lets you to control the page behaviour after submitting the form.
Upvotes: 1