Hola amigos de foros del web... tengo esta duda ....
Estoy validando un formulario con radio buttons, y quiero validar solo algunos de ellos... como este ejemplo...
prueba.html
Código HTML:
<html>
<head>
<title>NN</title>
<script language="JavaScript1.2" src="validar.js"></script>
</head>
<body>
<form action="#" method="post" name="formbeca" onSubmit="JavaScript:return Validar(formbeca)">
<table width="776" border="0" cellpadding="0" cellspacing="0" background="http://www.forosdelweb.com/images/fondo2a.jpg" align="center">
<tr>
<td>
<table align="left" width="76%" border=1 cellspacing=0 cellpadding=2 bordercolor="666633">
<tr>
<td width="9%" align="center">10</td>
<td width="67%"> Padre:</td>
<td width="24%" align="center"><input type="radio" name="paren" value="1" checked></td>
</tr>
<tr>
<td width="9%" align="center">11</td>
<td width="67%"> Madre:</td>
<td width="24%" align="center"><input type="radio" name="paren" value="2"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
<table width="70%" align="left" border=1 cellspacing=0 cellpadding=2 bordercolor="666633">
<tr>
<td align="center">151</td>
<td width="47%"> ¿Pertenece al Programa Puente?</td>
<td width="12%" align="center"><input type="radio" name="puente"></td>
<td width="12%" align="center"><input type="radio" name="puente" checked></td>
<td width="17%" align="center"><input type="text" maxlength="9" size="10" name="valor1"></td>
</tr>
<tr>
<td align="center">152</td>
<td width="47%"> ¿Pertenece al Programa Chile Solidario?</td>
<td width="12%" align="center"><input type="radio" name="chile"></td>
<td width="12%" align="center"><input type="radio" name="chile" checked></td>
<td width="17%" align="center"><input type="text" maxlength="9" size="10" name="valor2"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center"><input type="submit" name="submit" value="Ingresar Formulario"></td>
</tr>
</table>
</form>
</body>
</html>
El problema es validar los radio chile y puente... en el javascript no puedo hacer la validación que si selecciono SI en los dos radio (chile y puente) le ingrese un valor entero, valida cada uno solo.. pero si quiero validar los 2 no valida bien....
Les paso el javascript.... para que vean lo que pasa...
validar.js
Código HTML:
// JavaScript Document
function Validar(formbeca) {
return (
ValidarBenef1() && ValidarBenef2())
}
function ValidarBenef1(){
var cadena = "Uno de los montos del beneficio no es válido.\n"
+ "Revisar por favor. ";
if(document.formbeca.puente[0].checked){
val1=document.formbeca.valor1.value;
if(isNaN(val1)){
alert(cadena);
document.formbeca.valor1.focus();
return false;
}
}else return true;
}
function ValidarBenef2(){
var cadena = "Uno de los montos del beneficio no es válido.\n"
+ "Revisar por favor. ";
if(document.formbeca.chile[0].checked){
val2=document.formbeca.valor2.value;
if(isNaN(val2)){
alert(cadena);
document.formbeca.valor2.focus();
return false;
}
}else return true;
}
espero que me puedan guiar en este problema... de antemano muchas gracias !!!