I'm trying to do a function in javascript to validate a form, I want it the function scroll through the form and check which fields are required (required) and then add those fields to a list and then manipulate and handle the errors:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<!--JQUERY AND BOOSTRAP-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><linkrel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<!--JS-->
<script src="function.js"></script>
</head>
<body>
<form id="formTeste">
<div class="col-sm-4">
<label for="textoObrigatorio">Texto Obrigatorio</label>
<input type="text" id="textoObrigatorio" required />
</div>
<button type="button" onclick="ValidarFormulario('formTeste')">Validar</button>
</form>
</body>
</html>
Javascript
function ValidarFormulario(idForm) {
var formulario = document.getElementById(idForm);
//PERCORRER O FORMULARIO
//VERIFICAR OS ELEMENTOS OBRIGATORIOS
}
The difficulty is where to find input elements within the form?