0
Good,
I’m having trouble with an html form where the data doesn’t go empty to the comic. I have Javascript but it is not working correctly.
Jsfield: https://jsfiddle.net/ogr6oa0t/
Code:
<form action="NovoCliente.php" method="post" onsubmit="return validar();">
<p><label class="formulario">Nome </label><input type="text" name="Nome" size="50" maxlength="30"></p>
<p><label class="formulario">Password </label><input type="password" name="Password" size="50" maxlength="30"></p>
<p><label class="formulario">Número de BI </label><input type="Number" name="NumeroBI" size="50" maxlength="30"></p>
<p><label class="formulario">Morada </label><input type="text" name="Morada" size="50" maxlength="30"></p>
<p><label class="formulario">Telefone </label><input type="text" name="Telefone" size="50" maxlength="30"></p>
<p><label class="formulario">Data de Nascimento </label><input type="Date" name="DataNasc"></p>
<p><label class="formulario">Email </label><input type="text" name="Email" size="50" maxlength="30"></p>
<input type="reset" value="Limpar">
<input type="submit">
</form>
Script:
<script>//Script para validar dados do Registo
function validar(){
if(document.ficha.nome.value.length == 0)
{
alert("Falta nome");
return false;
}
if( isNaN (document.ficha.numbi.value.length == 0))
{
alert("Sรณ numeros");
return false;
}
else if (document.ficha.numbi.value.length < 8)
{
alert("Faltam numeros");
return false;
}
if(document.ficha.correio.value.indexOf("@") == -1)
{
alert("Email Invalido");
return false;
}
}
</script>
Missed putting the
name="ficha"
.– Ivan Ferrer
Just be aware that even if you validate in Javascript, you should still validate in the server language (php, Asp, etc).
– Daniel Omine