Tenho o seguinte formulario em HTML:
<form name ="form" class="signupform" action="signup.php" method="post" onsubmit="Valitedata()" enctype="multipart/form-data" autocomplete="off">
<p><u>Create an account</u></p>
<div class="form-container">
<span class="input-label">Name:</span><input id="name" type="text" placeholder="Name" name="name"><br>
<span class="input-label">Surname:</span><input id="surname" type="text" placeholder="surname" name="surname"><br>
<span class="input-label">Email:</span><input id="email" type="email" placeholder="Email" name="email"><br>
<span class="input-label">Door Number:</span><input id="doornumber" type="text" placeholder="Door number" name="doornumber"><br>
<span class="input-label">Road:</span><input id="road" type="text" placeholder="road" name="road"><br>
<span class="input-label">Post Code:</span><input id="postcode" type="text" placeholder="post code" name="postcode"><br>
<span class="input-label">Password:</span><input id="password" type="password" placeholder="Password" name="password"> <br>
<span class="input-label">Confirm Password:</span><input id="cpassword" type="password" placeholder="Confirm Password" name="confirmpassword" autocomplete="new-password"> <br>
</div>
E estou a tentar fazer a validação em javascript:
function Validatedata()
{
var name = document.Validatedata.name;
var surname = document.Validatedata.surname;
var email = document.Validatedata.email;
var doornumber = document.Validatedata.doornumber;
var road= document.Validatedata.road;
var postcode = document.Validatedata.postcode;
var password = document.Validatedata.password;
var confirmpassword= document.Validatedata.confirmpassword;
var country = document.Validatedata.country;
var Address = document.Validatedata.Address;
var firstName = document.Validatedata.firstName;
var lastName = document.Validatedata.lastName;
var Email = document.Validatedata.Email;
var MobilePhone = document.Validatedata.MobilePhone;
if (name.value == "")
{
window.alert("Please enter a name.");
name.focus();
return false;
}
if (surname.value == "")
{
window.alert("Please enter a surname.");
surname.focus();
return false;
}
if (doornumber.value == "")
{
window.alert("Please enter door number.");
doornumber.focus();
return false;
}
if (road.value == "")
{
window.alert("Please enter road.");
road.focus();
return false;
}
if (postcode.value == "")
{
window.alert("Please enter postcode.");
postcode.focus();
return false;
}
if (country.value == "")
{
window.alert("Please enter country.");
country.focus();
return false;
}
if (Address.value == "")
{
window.alert("Please enter Address.");
Address.focus();
return false;
}
if (firstName.value == "")
{
window.alert("Please enter firstName.");
firstName.focus();
return false;
}
if (lastName.value == "")
{
window.alert("Please enter lastName.");
lastName.focus();
return false;
}
if (Email.value == "")
{
window.alert("Please enter Email.");
Email.focus();
return false;
}
if (MobilePhone.value == "")
{
window.alert("Please enter MobilePhone.");
MobilePhone.focus();
return false;
}
}
Mas esta validação que eu criei não está a fazer nada. Gostaria de dizer que esta validação tem outras "var" porque pretendo utilizar o ficheiro js com outros formularios.
Algum ideia do porque de não estar a funcionar.
Validatedata
.