This code works at the top of my website (menu), and I'm trying to use it in the footer as well, since I have the registry tab both at the top and in the footer, but in the footer it does not work.
Can anyone help me find the error? or is it simply impossible to use the same code at the top and in the footer? Remember that I'm creating all the separate pages (footer is one page, menu is another, and joining them with php.) For this reason, I believe, that should not make a mistake, since, supposedly, they are not in direct contact with a page with the other.
Can anyone help me with what I should do to make it work on both pages? Do I have to change or add something?
function valida_campos() {
if (document.getElementById('name').value == '') {
alert('The field name is obrigatory.');
document.getElementById('name').focus();
return false;
}
if (document.getElementById('lastname').value == '') {
alert('The field lastname is obrigatory.');
document.getElementById('lastname').focus();
return false;
}
if (document.getElementById('birthday').value == '') {
alert('Field birthday is obrigatory.');
document.getElementById('birthday').focus();
return false;
}
if (document.getElementById('email').value == '') {
alert('The field email obrigatory.');
document.getElementById('email').focus();
return false;
}
if (document.getElementById('password').value == '' || document.getElementById('password').value != document.getElementById('password2').value) {
alert('Password didnt mach, please try again.');
document.getElementById('password').focus();
return false;
}
}
<form class="default-form" action="cadastrar.php" method="post" onSubmit="return valida_campos();">
<p class="form-row">
<input name="name" id="name" type="text" placeholder="Name">
</p>
<p class="form-row">
<input name="lastname" id="lastname" type="text" placeholder="Last Name">
</p>
<p class="form-row">
<input name="birthday" id="birthday" type="text" placeholder="birthday d/m/y">
</p>
<p class="form-row">
<input name="email" id="email" type="text" placeholder="Email">
</p>
<p class="form-row">
<input name="password" id="password" type="password" placeholder="Password">
</p>
<p class="form-row">
<input name="password2" id="password2" type="password" placeholder="Repeat Password">
</p>
<input type="submit" placeholder="cadastrar">
</form>