Ver Mensaje Individual
  #5 (permalink)  
Antiguo 28/08/2008, 09:19
piyolo
 
Fecha de Ingreso: julio-2008
Mensajes: 66
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: Validar input text y un checkbox dentro de un mismo <tr>

Ya aquí está no era tan dificil, pero estaba (estoy) corto de tiempo...

Ojala a alguien le sirva, las funciones las saque de por ahí y las adapte a mi codigo
jsp
chau


<form action="" method="post" onSubmit="return validaCheck()">
<table id="tabla">

<%
int j =0;
while(result.next()){
%>

<tr>
<td>
<input type='checkbox' id='Parcial"+j+"'onClick='validaItem("+j+")'/>"
</td>
...
...
...
<td>
<span id='Parcial"+j+"obl' style='visibility:hidden;color:#ff0000;'>
<input type='text' id='InParcial"+j+"' value=''nKeypress='mis_datos()' />"
</span>
</td>
</tr>

<%
j++
} // End while
%>
<td>
<input type='submit' value='Entrega Parcial' onClick='return validaCheck()' />
</td>
</form>
<Script>
function mis_datos(){ // Funcion que solo deja que entren valores numericos
var key=window.event.keyCode;
if (key < 48 || key > 57){
window.event.keyCode=0;
}
}

function validaItem(j){ Funcion que hace visibles los campos input text, se llama en el onClick de los checkbox's
var i;
parcial=document.getElementById("Parcial"+j);
i=parcial.id+"obl";

if(parcial.checked){
document.getElementById(i).style.visibility="visib le";
}
else{
document.getElementById(i).style.visibility="hidde n";
valInput=document.getElementById("InParcial"+j);
valInput.value="";
}
}

function validaCheck(){ Verifica que se seleccione al menos un item's y al seleccionarlo verifica que el input text contenga un valor. Se llama en el evento onsubmit
chk=document.getElementById('tabla').getElementsBy TagName('input');
num=0;
for(i=0; i < chk.length; i++){
if(chk[i].checked){
num++;
auxParcial="In"+chk[i].id;
aux = document.getElementById(auxParcial);

if(aux.value == ""){
alert("Debe Ingresar un valor");
aux.focus();
}
}
}
if(num == 0){
alert("Debe seleccionar al menos un Item");
return false;
}
else
return true;
}


</Script>