1
I’m trying to validate a form with javascript using the event onsubmit
but, only when I do the validation it does not alert and sends the data in the same way and from what I am seeing there is nothing wrong in it on the console, so I realized that it’s jumping my if
, what wasn’t supposed to happen and he’s apparently right, so he wanted someone’s help to follow the code html and then the js:
HTML
<?php
include "index.php";
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Title Page</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="validar.js" type="text/javascript" charset="utf-8"></script>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<form action="inserir-dados.php" method="post" name="form" onSubmit="validar();">
<table border="0" class="table table-responsive">
<tr></tr>
<td>Nome <input type="text" name="nome" id="Cnome" maxlength="32" placeholder="Nome da pessoa" size="58" required></td>
</tr>
<tr>
<td>Idade <input type="number" name="idade" id="Cidade" placeholder="Idade da pessoa" required></td>
</tr>
<tr>
<td>Telefone <input type="number" name="telefone" id="Ctelefone" placeholder="XXX-XXXX-XXXX" required>
</td>
</tr>
<tr>
<td>Endereço <input type="text" name="endereço" id="Cendereço" maxlength="34" placeholder="Endereço da pessoa"
required> </td>
</tr>
<tr>
<td>Cidade <input type="text" name="cidade" id="Ccidade" maxlength="24" placeholder="Cidade da pessoa" required> </td>
</tr>
<tr>
<td>Estado</td>
</tr>
<tr>
<td>
<select class="btn btn-default" name="estado" id="Cestado">
<option>SP</option>
<option>MG</option>
<option>RJ</option>
<option>SC</option>
<option>BA</option>
<option>CE</option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" value="Enviar"class="btn btn-primary"><input type="reset" Value="Limpar" class="btn btn-danger"></td>
</tr>
</table>
</form>
<!-- jQuery -->
<script src="//code.jquery.com/jquery.js"></script>
<!-- Bootstrap JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
</body>
</html>
JS
function validar(){
if(document.form.telefone.value.lenght <11){
alert("Esse campo precisa de 11 caracteres");
document.form.telefone.focus();
return false;
}
}
friend was just that I was not getting changed but,it ta sending form the same way even returning false
– Adriano Rufino
The problem has been solved?
– Leonardo Barros
was solved as I close the topical?
– Adriano Rufino
If any answer quallifique as correct, you mark as correct, or you can answer your question.
– Vinicius De Jesus