Foros del Web » Programando para Internet » Javascript »

Igualar Botones de Formulario, URGENTE!!

Estas en el tema de Igualar Botones de Formulario, URGENTE!! en el foro de Javascript en Foros del Web. Hola, tengo un formulario y quiero igualar algunos campos de texto y botones de seleccion (radio), No logro igualar los botones de seleccion solo los ...
  #1 (permalink)  
Antiguo 10/02/2008, 01:46
 
Fecha de Ingreso: septiembre-2007
Mensajes: 150
Antigüedad: 17 años, 4 meses
Puntos: 1
Exclamación Igualar Botones de Formulario, URGENTE!!

Hola, tengo un formulario y quiero igualar algunos campos de texto y botones de seleccion (radio),

No logro igualar los botones de seleccion solo los campos de texto

hice esto (que estara mal)::

Código HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <p>
    <label></label>
    </p>
  <table width="200" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>Primero</td>
      <td><input name="nombre1" type="text" id="nombre1" value="Juanito Perez" /></td>
    </tr>
    <tr>
      <td>Segundo</td>
      <td><input type="text" name="nombre2" id="nombre2" /></td>
    </tr>
  </table>
  <br />
  <table width="200" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>Primero</td>
      <td><input name="radio1" type="radio" id="radio" value="Si" checked="checked" />
        <input type="radio" name="radio1" id="radio" value="No"/></td>
    </tr>
    <tr>
      <td>Segundo</td>
      <td><input type="radio" name="radio2" id="radio2" value="Si"/>
        <input type="radio" name="radio2" id="radio2" value="No"/></td>
    </tr>
  </table>
  <p>
    <input type="button" name="enviar" onclick="nombre2.value=nombre1.value; radio2.value=radio1.value; " value="Enviar Datos" id="enviar" />
  </p>
  <p>&nbsp;</p>
</form>
</body>
</html> 
  #2 (permalink)  
Antiguo 10/02/2008, 02:21
Avatar de caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 22 años, 10 meses
Puntos: 1284
Re: Igualar Botones de Formulario, URGENTE!!

Hola:

Los radios debes controlarlos con su checked, pero no vale con distinto nombre, así que es mejor controlarlos por su id (que por cierto, no deben duplicarse)

por ejemplo puedes usar los id: radio[1/4], y para simplificar poner un alias al document.getElementById...
<script>
function tag(id) {return document.getElementById(id);}

...

Luego la valídación sería:
<form onsubmit="return tag('radio1').checked == tag('radio3').checked" ...

Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo
  #3 (permalink)  
Antiguo 10/02/2008, 11:27
 
Fecha de Ingreso: septiembre-2007
Mensajes: 150
Antigüedad: 17 años, 4 meses
Puntos: 1
Exclamación Re: Igualar Botones de Formulario, URGENTE!!

Pepe: Lo hice como me dijiste pero no funciona...

Asi lo hice, donde estara mi error?

Código HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>
<script language="JavaScript">
function tag(id) {return document.getElementById(id);
}
</script>

<body>
<form id="form1" name="form1" method="post" action="">
  <p>
    <label></label>
    </p>
  <table width="200" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>Primero</td>
      <td><input name="nombre1" type="text" id="nombre1" value="Juanito Perez" /></td>
    </tr>
    <tr>
      <td>Segundo</td>
      <td><input type="text" name="nombre2" id="nombre2" /></td>
    </tr>
  </table>
  <br />
  <table width="200" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>Primero</td>
      <td><input name="radio1" type="radio" id="radio1" value="Si" checked="checked" />
        <input type="radio" name="radio1" id="radio1" value="No"/></td>
    </tr>
    <tr>
      <td>Segundo</td>
      <td><input type="radio" name="radio2" id="radio2" value="Si2"/>
        <input type="radio" name="radio2" id="radio2" value="No2"/></td>
    </tr>
  </table>
  <p>
    <input type="button" name="enviar" onclick="nombre2.value=nombre1.value; return tag('radio2').checked == tag('radio1').checked; " value="Enviar Datos" id="enviar" />
  </p>
  <p>&nbsp;</p>
</form>
</body>
</html> 
  #4 (permalink)  
Antiguo 10/02/2008, 11:41
Avatar de Bellenger  
Fecha de Ingreso: noviembre-2004
Ubicación: En un lugar del Mundo...
Mensajes: 599
Antigüedad: 20 años, 2 meses
Puntos: 4
Re: Igualar Botones de Formulario, URGENTE!!

Lo id de los radios deben ser distintos, nunca iguales como dijo Caricato...
__________________
Un Caballero Jura Lealtad. Usa su espada para suprimir la Injusticia No Conoce el Odio y Tampoco el AMOR...
  #5 (permalink)  
Antiguo 10/02/2008, 11:52
 
Fecha de Ingreso: septiembre-2007
Mensajes: 150
Antigüedad: 17 años, 4 meses
Puntos: 1
Re: Igualar Botones de Formulario, URGENTE!!

Le cambie el nombre a los id pero no pasa nada:

Código HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>
<script language="JavaScript">
function tag(id) {return document.getElementById(id);
}
</script>

<body>
<form id="form1" name="form1" method="post" action="">
  <p>
    <label></label>
    </p>
  <table width="200" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>Primero</td>
      <td><input name="nombre1" type="text" id="nombre1" value="Juanito Perez" /></td>
    </tr>
    <tr>
      <td>Segundo</td>
      <td><input type="text" name="nombre2" id="nombre2" /></td>
    </tr>
  </table>
  <br />
  <table width="200" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>Primero</td>
      <td><input type="radio" name="radio1" id="radio1" value="Si" checked="checked" />
        <input type="radio" name="radio1" id="radio2" value="No"/></td>
    </tr>
    <tr>
      <td>Segundo</td>
      <td><input type="radio" name="radio3" id="radio3" value="Si2"/>
        <input type="radio" name="radio3" id="radio4" value="No2"/></td>
    </tr>
  </table>
  <p>
    <input type="button" name="enviar" onclick="nombre2.value=nombre1.value; return tag('radio1').checked == tag('radio3').checked; " value="Enviar Datos" id="enviar" />
  </p>
  <p>&nbsp;</p>
</form>
</body>
</html> 
  #6 (permalink)  
Antiguo 10/02/2008, 16:25
Avatar de caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 22 años, 10 meses
Puntos: 1284
Re: Igualar Botones de Formulario, URGENTE!!

Hola:

Las validaciones por regla general deben hacerse en el tag form (tal como puse más arriba)...

Prueba así:

Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>
<script language="JavaScript">
function tag(id) {return document.getElementById(id);
}
</script>

<body>
<form id="form1" name="form1" method="post" action="" onsubmit="return (nombre2.value==nombre1.value) && (tag('radio1').checked == tag('radio3').checked)">
  <p>
    <label></label>
    </p>
  <table width="200" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>Primero</td>
      <td><input name="nombre1" type="text" id="nombre1" value="Juanito Perez" /></td>
    </tr>
    <tr>
      <td>Segundo</td>
      <td><input type="text" name="nombre2" id="nombre2" /></td>
    </tr>
  </table>
  <br />
  <table width="200" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>Primero</td>
      <td><input type="radio" name="radio1" id="radio1" value="Si" checked="checked" />
        <input type="radio" name="radio1" id="radio2" value="No"/></td>
    </tr>
    <tr>
      <td>Segundo</td>
      <td><input type="radio" name="radio3" id="radio3" value="Si2"/>
        <input type="radio" name="radio3" id="radio4" value="No2"/></td>
    </tr>
  </table>
  <p>
    <input type="submit" name="enviar" value="Enviar Datos" id="enviar" />
  </p>
  <p>&nbsp;</p>
</form>
</body>
</html>
Tienes algunas cosas mal... el return debe implicar todas las comparaciones, debe estar en el tag form (onsubmit); el botón siempre debe ser tipo submit...

Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo
  #7 (permalink)  
Antiguo 10/02/2008, 19:22
 
Fecha de Ingreso: septiembre-2007
Mensajes: 150
Antigüedad: 17 años, 4 meses
Puntos: 1
Exclamación Re: Igualar Botones de Formulario, URGENTE!!

Lo que pasa es que no quiero que me envie el formulario, quiero que me los iguale en pantalla Onclik no Onsubmit, pero no se como se hara CON UN BOTON QUE NO SEA TIPO SUBMIT.



Cita:
Iniciado por caricatos Ver Mensaje
Hola:

Las validaciones por regla general deben hacerse en el tag form (tal como puse más arriba)...

Prueba así:

Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>
<script language="JavaScript">
function tag(id) {return document.getElementById(id);
}
</script>

<body>
<form id="form1" name="form1" method="post" action="" onsubmit="return (nombre2.value==nombre1.value) && (tag('radio1').checked == tag('radio3').checked)">
  <p>
    <label></label>
    </p>
  <table width="200" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>Primero</td>
      <td><input name="nombre1" type="text" id="nombre1" value="Juanito Perez" /></td>
    </tr>
    <tr>
      <td>Segundo</td>
      <td><input type="text" name="nombre2" id="nombre2" /></td>
    </tr>
  </table>
  <br />
  <table width="200" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>Primero</td>
      <td><input type="radio" name="radio1" id="radio1" value="Si" checked="checked" />
        <input type="radio" name="radio1" id="radio2" value="No"/></td>
    </tr>
    <tr>
      <td>Segundo</td>
      <td><input type="radio" name="radio3" id="radio3" value="Si2"/>
        <input type="radio" name="radio3" id="radio4" value="No2"/></td>
    </tr>
  </table>
  <p>
    <input type="submit" name="enviar" value="Enviar Datos" id="enviar" />
  </p>
  <p>&nbsp;</p>
</form>
</body>
</html>
Tienes algunas cosas mal... el return debe implicar todas las comparaciones, debe estar en el tag form (onsubmit); el botón siempre debe ser tipo submit...

Saludos
  #8 (permalink)  
Antiguo 10/02/2008, 23:48
Avatar de caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 22 años, 10 meses
Puntos: 1284
Re: Igualar Botones de Formulario, URGENTE!!

Hola:

Entonces puedes usar un botón normal... pensaba que lo que querías era una especie de validación... creo que me despisté con el input "enviar".
Entonces los nombres veo que los iguales bien, así que quedaría igualar los radios... serían simples asignaciones de valores lógicos:
onclick="nombre2.value = nombre1.value; tag('radio3').checked = tag('radio1').checked; tag('radio4').checked = tag('radio2').checked"

Creo que no valdría la asignación en uno solo.

Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo
  #9 (permalink)  
Antiguo 11/02/2008, 13:17
 
Fecha de Ingreso: septiembre-2007
Mensajes: 150
Antigüedad: 17 años, 4 meses
Puntos: 1
Exclamación Re: Igualar Botones de Formulario, URGENTE!!

Gracias Pepe, funciono las mil maravillas, te debo otra mas.

Pd: Serias tan amable de darte una vuelta por un mensaje que publique ya que hasta la fecha no he tenido solucion.

Código HTML:
http://www.forosdelweb.com/f13/completar-inputbox-apretar-boton-ayuda-urgente-555840/
Saludos.
  #10 (permalink)  
Antiguo 11/02/2008, 13:26
Avatar de caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 22 años, 10 meses
Puntos: 1284
Re: Igualar Botones de Formulario, URGENTE!!

Hola:

Me alegro de que ya tengas solucionado el problem.

Sobre el otro tema, lo estuve viendo, y la respuesta que te dió JavierB es la misma que se me ocurre... sigue con ese mensaje, dándo más datos (pon lo que php genera en esa etiqueta)

Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo
  #11 (permalink)  
Antiguo 11/02/2008, 14:03
 
Fecha de Ingreso: septiembre-2007
Mensajes: 150
Antigüedad: 17 años, 4 meses
Puntos: 1
Exclamación Re: Igualar Botones de Formulario, URGENTE!!

Oka, gracias por el consejo, adjunte los archivos en el otro tema, para ver si le pegas una mirada.

Saludos.
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 14:16.