Muchos de nostros hemos tenido alguna vez problemas validando checkList en Javascript, a continuacion les dejo un metodo simple y consiso sobre como hacerlo.
function Aceptar() {
var datos = '';
var lista = '';
if (validardatos()) {
var chkList = document.getElementById('chkList');
var chk = chkList.getElementsByTagName("input");
for (var i = 0; i < chk.length; i++) {
if (chk[i].checked) {
datos = chk[i].value;
lista = lista + '<@articulo@>' + datos;
}
}
}
window.opener.RetornarArticulo(lista);
window.close();
}
function validardatos() {
var chkList = document.getElementById('chkList');
var chk = chkList.getElementsByTagName("input");
for (var i = 0; i < chk.length; i++ ) {
if (chk[i].checked == true) {
return true;
}
}
alert("Seleccione al menos un Articulo");
return false;
}
Son dos funciones en Javascript una que valida y otra que envia los datos de las opcviones seleccionadas a la pagina anterior.
No hay comentarios:
Publicar un comentario