1
I implemented a simple valid to check if the input matches the rules and if it is negative it should be in focus to change the data, but the focus is not working, it leaves the next item in focus and not what was set in javascript, I already removed the required and still does not work follow the code I am using.
function verificaForm() {
//var doc = document.getElementById('txtName').value;
//alert(doc);
if (document.formulario.txtName.value === "") {
alert('Campo nome vazio');
//document.getElementById('txtName').focus();
var nome = document.getElementById('txtName');
document.getElementById('txtName').focus();
return false;
}
return true;
}
<form class="form" name="formulario" method="post">
<div class="form-control">
<label for="txtName">Nome:</label>
<input type="text" id="txtName" name="txtName">
</div>
<div class="form-control">
<label for="txtSobrenome">Sobre-nome</label>
<input type="text" id="txtSobrenome" name="txtSobrenome">
</div>
<div class="form-control">
<label for="txtIdade">Idade</label>
<input type="text" id="txtIdade" name="txtIdade">
</div>
<div class="form-control">
<button class="btn btn-danger" onclick="verificaForm()">Verificar ...</button>
</div>
</form>
Here’s a good one reply.
– Marconi