JavaScript - Validacion FOrm

 
Vista:

Validacion FOrm

Publicado por Gustavo (12 intervenciones) el 02/03/2007 15:14:49
hola necesito validar este formulario,pero me no lo puede hacer,se me complica,Quiero que me de error si no eligio ningun radio o checkbox y si el campo de texto esta vacio.
Y nose como hacerlo,Espero alguien pueda ayudarme este es el codigo:

<html>
<head>
<script language="javascript">
function validar(){
theform=document.form1;
for(i=0;i<theform.elements.length;i++){
if(theform.elements[i].checked==false && theform.elements[i].type=="radio"){
alert("error");
return false
}else{
return true;
}
}


}
</script>
</head>
<BODY>
<form name="form1" method="post" action="#">
<input type="radio" name="rad">
<input type="radio" name="rad">
<input type="radio" name="rad">
<input type="radio" name="rad">
<br>
<br>
<input type="checkbox" name="chk"><br>
<input type="checkbox" name="chk_1"><br>
<input type="text" name="usuario">

<input type="submit" value="enviar" onClick="return validar()">
</form>
</BODY>
</HTML>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder