Skip to content

Instantly share code, notes, and snippets.

@aranajhonny
Created November 28, 2016 23:35
Show Gist options
  • Save aranajhonny/8d655d86dc72caaeb075d35b8663b993 to your computer and use it in GitHub Desktop.
Save aranajhonny/8d655d86dc72caaeb075d35b8663b993 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
window.onload = function () {
document.crear_producto.focus();
document.crear_producto.addEventListener('submit', validarFormulario);
}
function validarFormulario(evObject) {
evObject.preventDefault();
var todoCorrecto = true;
var formulario = document.crear_producto;
for (var i=0; i<formulario.length; i++) {
if(formulario[i].type =='text') {
if (formulario[i].value == null || formulario[i].value.length == 0 || /^\s*$/.test(formulario[i].value)){
swal ('No puede haber campos vacíos');
todoCorrecto=false;
}
}
}
if (todoCorrecto ==true) {formulario.submit();}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment