6
I have a validation error when I press the button input
of submit
he does not test the function
Javascript and goes right to where the action
is telling to go.
<HTML>
<HEAD>
<TITLE>Cadastro</title>
<script language="JavaScript">
function validaFormCadastro() {
d = document.form_cadastro;
if (d.NOME.value == "") {
alert("O campo NOME deve ser preenchido!");
d.NOME.focus();
return false;
}
if (d.NOMEUSUARIO.value == "") {
alert("O campo NOME DE USUARIO deve ser preenchido!");
d.NOMEUSUARIO.focus();
return false;
}
if (d.RM.value == "") {
alert("O campo RM deve ser preenchido!");
d.RM.focus();
return false;
}
if (d.SENHA.value == "") {
alert("O campo SENHA deve ser preenchido!");
d.SENHA.focus();
return false;
}
}
</script>
</head>
<body>
<form name="form_cadastro" action="salvar_aluno.php" method="get">
<table border='1'>
<tr>
<td>
<label>Nome completo</label>
</td>
<td>
<input type="text" name="NOME">
<br>
</td>
</tr>
<tr>
<td>
<label>Nome de Usuario</label>
</td>
<td>
<input type="text" name="NOMEUSUARIO">
<br>
</td>
</tr>
<tr>
<td>
<label>RM</label>
</td>
<td>
<input type="text" name="RM">
<br>
</td>
</tr>
<tr>
<td>
<label>SENHA</label>
</td>
<td>
<input type="password" name="SENHA">
<br>
</td>
</tr>
</table>
<p>
<input type="submit" name="botao_comando" value="CADASTRAR" onclick="return validaFormCadastro()">
</form>
</body>
</html>
Boy, your role is being loaded, both in a file I created to test, and in this Jsfiddle: http://jsfiddle.net/SamirChaves/asd7ddt3/1/ test and see if this is really your problem
– Samir Braga
Try to change the
d = document.form_cadastro
ford = document.forms.id_form_cadastro
, in case, it would be an id, not the name.– ptkato
Your form has an input
type="submit"
, soon will ignore the existing js, and proceed with sending the form. One of the solutions would be to put a replace the eventonclick
of that button, for aonblur
.– Edilson
Here worked normally, probably is some other script that is error and the rest of javascript does not process.
– Guilherme Nascimento