Foros del Web » Programando para Internet » Javascript »

Como Valido opciones de Radio ?

Estas en el tema de Como Valido opciones de Radio ? en el foro de Javascript en Foros del Web. Que tal, Yo utilizo el validador de Tunait que va muy bien. Ahora necesito hacer un formulario especial, tipo encuesta que solo tiene botones de ...
  #1 (permalink)  
Antiguo 31/10/2005, 08:55
 
Fecha de Ingreso: octubre-2005
Mensajes: 365
Antigüedad: 18 años, 6 meses
Puntos: 0
Como Valido opciones de Radio ?

Que tal,

Yo utilizo el validador de Tunait que va muy bien. Ahora necesito hacer un formulario especial, tipo encuesta que solo tiene botones de radio y éste verificador no verifica objetos de formulario tipo radio.............. que código javascript se usa para verificar que mis opciones de radio sean llenadas?


Saludos y gracias de antemano


http://javascript.tunait.com/javascr...dorformularios
  #2 (permalink)  
Antiguo 31/10/2005, 09:07
 
Fecha de Ingreso: octubre-2005
Mensajes: 365
Antigüedad: 18 años, 6 meses
Puntos: 0
Ah bueno en las FAQS he visto este pero no me funciona:

Código PHP:
<script language="JavaScript">
var 
el document.(form1).elements;
for (var 
el.length ; ++i) {
    if (
el[i].type == "radio") {
        var 
radiogroup el[el[i].name];
        var 
itemchecked false;
        for (var 
radiogroup.length ; ++j) {
            if (
radiogroup[j].checked) {
            
itemchecked true;
            break;
            }
        }
        if (!
itemchecked) {
            
i=0;
            break;
        }
    }
}
if (
i>0) {
    return 
true;
} else {
    
alert("No ha respondido todas las preguntas");
    return 
false;

</script> 
Osea no sé como adaptarlo a mi formularo, ya le he puesto el nombre en la opción:

Código PHP:
var el document.(form1).elements
No sé que más hacer...
  #3 (permalink)  
Antiguo 31/10/2005, 09:10
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 20 años, 11 meses
Puntos: 5
que tal sofia_me_gusta?? de vuelta por ak?? que tal
yo puse algo de eso en los FAG's por si te sirve...

http://www.forosdelweb.com/showpost....&postcount=226

saludos
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #4 (permalink)  
Antiguo 31/10/2005, 11:53
 
Fecha de Ingreso: octubre-2005
Mensajes: 365
Antigüedad: 18 años, 6 meses
Puntos: 0
Mi form se llama form1

Código PHP:
<script language="javascript">
function 
validar_checkbox() {
var 
total f.form1.length;
var 
selected false;

if (
total != null) {
for (
i=0i<totali++) {
    if (
f.form1[i].checked == true) {
     
selected true;
     break;
    }
}
} else {
if (
f.form1.checked == true) {
    
selected true;
}
}

if (
selected == false) {
alert("Debe seleccionar al menos una opción.");
return 
false
}
}
</script> 

Y en el form pongo:

Código PHP:
<form name="form1" method="post" action="algo.asp" onSubmit="return validar_checkbox()"

Pero no funciona, que puede ser? Lo mio son botones de radio no checkboxes, funciona igual ?
  #5 (permalink)  
Antiguo 31/10/2005, 12:09
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 20 años, 11 meses
Puntos: 5
Cita:
Iniciado por SOFIA_ME_GUSTA
Pero no funciona, que puede ser? Lo mio son botones de radio no checkboxes, funciona igual ?
como se llaman los checkboxes?.... alli no veo nada de eso
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #6 (permalink)  
Antiguo 31/10/2005, 12:39
 
Fecha de Ingreso: octubre-2005
Mensajes: 365
Antigüedad: 18 años, 6 meses
Puntos: 0
Mmmmmm ha de ser eso, una ayuda, en qué parte de éste código se colocan los nombres de los radiogroups ?
  #7 (permalink)  
Antiguo 31/10/2005, 17:28
Avatar de Cap.Buscapina  
Fecha de Ingreso: octubre-2004
Ubicación: Argentina
Mensajes: 836
Antigüedad: 19 años, 6 meses
Puntos: 4
holas.

si bien no es muy "ortodoxo" ni muy "elegante" yo lo haría así (a lo mejor te sirve)

Cita:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
function verif(){
aa=0;
formu=document.forms['form1'];
cuantos=3;//cuantos grupos de radiobuttons
for(x=1;x<cuantos+1;x++){
if(formu['q'+x].value==""){aa=1;}
}
(aa==0)?formu.submit():alert('incorrecto');
}



function definir(cual,valor){
document.forms['form1'][cual].value=valor;
}

</script>

</head>

<body>
<p>Cap_Buscapina es:</p>
<form name="form1" method="post" action="asda.asp">
<p>
<input type="radio" name="grupo1" value="hermoso" onClick="definir('q1',this.value)">
hermoso
<input type="radio" name="grupo1" value="feito" onClick="definir('q1',this.value)">
feito
<input name="q1" type="hidden" id="q1">
</p>
<p>
<input type="radio" name="grupo2" value="sexy" onClick="definir('q2',this.value)">
sexy
<input type="radio" name="grupo2" value="seco" onClick="definir('q2',this.value)">
mas_seco_que_bizcocho
<input name="q2" type="hidden" id="q2">
</p>
<p>
<input type="radio" name="grupo3" value="alegre" onClick="definir('q3',this.value)">
alegre
<input type="radio" name="grupo3" value="aburrido" onClick="definir('q3',this.value)">
aburrido
<input name="q3" type="hidden" id="q3">
</p>
<input name="enviar" value="enviar" type="button" onClick="verif()"></form>
<p>&nbsp;</p>
<p>&nbsp; </p>
<p>&nbsp; </p>
</body>
</html>

suerte
__________________
by Capitán Buscapina
.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:49.