Foros del Web » Programando para Internet » Javascript »

alguien q me ayude con esto

Estas en el tema de alguien q me ayude con esto en el foro de Javascript en Foros del Web. hola a todos tengo un problemita con la validacion del formulario q es cuando le doy clik al boton de GENERAR REPORTE si no hay ...
  #1 (permalink)  
Antiguo 22/06/2009, 07:24
Avatar de darwin_le  
Fecha de Ingreso: mayo-2009
Mensajes: 63
Antigüedad: 15 años
Puntos: 0
De acuerdo alguien q me ayude con esto

hola a todos tengo un problemita con la validacion del formulario q es cuando le doy clik al boton de GENERAR REPORTE si no hay un radio marcado tiene q aparecerme un mensaje q tiene q elegir un radio y cuando elijo uno y le doy al boton el msj me sale pero le doy aceptar y me dentra a la pagina eso no me deberia pasar ayudamen
aqui les dejo mi codigo:

Código HTML:
<head>
<SCRIPT LANGUAGE="JavaScript">
function validarFormulario() {
  var form = document.formulario;
  var s = "no";
  for ( var i = 0; i < form.salario.length; i++ ) {
    if ( form.salario.checked ) {
    s= "si";
    break;
    }
  }
  if ( s == "no" ){
    alert( "Debe seleccionar una opcion" ) ;
  }
}
</SCRIPT> 
<body>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>

<table width="100%" border="0" cellspacing="0" cellpadding="0" center>
  <tr>
    <td width="254"><div align="left"><img src="imagenes/top21.jpg" width="254" height="75" /></div></td>
    <td width="" align="right" valign="bottom" class="mainhead Estilo74" title="Consulta Recibo de pago"><div align="center"><center><h3><font face="arial"><font color="#317bae">Consulta de Empleado </font></div></td>
    <td width="300" title="Consulta Recibo de pago"><div align="right"><img src="imagenes/nomsistema.jpg" width="329" height="75" border="0" /></div></td>
	<td width="80" title="Gerencia de Automatización de Servicios"><div align="right"><img src="imagenes/gas.jpg" width="80" height="75" border="0" /></div></td>
  </tr>
  <tr>
    <td colspan="4" style="background-color:#317bae; filter:progid:DXImageTransform.Microsoft.Gradient(endColorstr='#317bae', startColorstr='#ffffff', gradientType='1')">&nbsp;</td>
  </tr>
</table>

<table width="200" border="0" align="right">
          <tr>
            <td><a href="menupri.php"><h4 align="center">Volver</h4></a></td>
          </tr>
</table>
<br />
<br />
<form  method="post" name="formulario" action="siguiente.php?cedula=<?php echo $row_constancia['cedula'];?>" >
<br />
<br />
<br />
<table width="48%" border="0" align="center" class="Estilo9">
<tr>
    <th scope="col" colspan="0" align="center" class="subtitulo2" bgcolor="#317bae"><p align="center"> Elija la Siguente Opcion opci&oacute;n: </p></th>
</tr>
<tr>
    <th width="0%" height="0"scope="row" ><label>
  	<input name="salario" type="radio" value="1"/>
    Sin Salario</label>&nbsp;</th>
    <th width="0%"scope="row" ><label>
  	<input name="salario" type="radio" value="2"/>
  	Con Salario Basico</label>&nbsp;</th>
	<th width="0%"scope="row"><label>
	<?php if (($anio > 1) or(($tipopersonal!=05) and ($tipopersonal!=06) and ($tipopersonal!=07))){ 
	echo "<input name='salario' type='radio' value='3'/>
	Con Salario Integral Estimado";} ?></label>&nbsp;</th>
</tr>
<tr>
	<th height="38" colspan="0" align="center"  bgcolor="#317bae" class="subtitulo2"><p align="center"><strong>Si 										quiere 	con Cesta Tiket Elija la Siguente Opcion opci&oacute;n: </p>
</tr>
<tr>
	<th height="25" colspan="0" align="center" class="subtitulo2"><p align="center"><strong><label>
	<input type="checkbox" name="ticket" value="1"/>
	Con Cesta Tiket</label></th>
</tr>
</table>
<br />
<br />
<table align="center">
<p>
  <th align="center"><label>
    <input type="submit" name="Submit" value="GENERAR REPORTE" onClick="validarFormulario()" />
    </label></th>
  </p>
 </table>
</form>
</body>
</head>
</html> 
  #2 (permalink)  
Antiguo 22/06/2009, 08:12
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: alguien q me ayude con esto

Hola

Prueba así

Código javascript:
Ver original
  1. function validar (c) {
  2.       for (var i=0; chk = c.ckb[i]; i++)
  3.     if (chk.checked) return;
  4.     alert("Has de selecionar uno");
  5.     return false;
  6. }

Código html:
Ver original
  1. onsubmit="return validar(this);"

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #3 (permalink)  
Antiguo 22/06/2009, 08:33
Avatar de darwin_le  
Fecha de Ingreso: mayo-2009
Mensajes: 63
Antigüedad: 15 años
Puntos: 0
Respuesta: alguien q me ayude con esto

no mi pana nada una pregunta q coloco en onClick y ese onsubmit="return validar(this);" a dond lo coloco
  #4 (permalink)  
Antiguo 22/06/2009, 12:14
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: alguien q me ayude con esto

Hola

Has de validarlo en el submit, así que quita el onclick

Código html:
Ver original
  1. <form  method="post" name="formulario" action="siguiente.php?cedula=<?php echo $row_constancia['cedula'];?>" onsubmit="return validar(this);">

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #5 (permalink)  
Antiguo 22/06/2009, 12:58
Avatar de darwin_le  
Fecha de Ingreso: mayo-2009
Mensajes: 63
Antigüedad: 15 años
Puntos: 0
Respuesta: alguien q me ayude con esto

hola

amigo nada no hay otra opcion de como hacerlo
  #6 (permalink)  
Antiguo 22/06/2009, 13:09
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: alguien q me ayude con esto

Hola

Muestra como te ha quedado

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #7 (permalink)  
Antiguo 22/06/2009, 13:15
Avatar de darwin_le  
Fecha de Ingreso: mayo-2009
Mensajes: 63
Antigüedad: 15 años
Puntos: 0
Respuesta: alguien q me ayude con esto

Código:
<head>
<SCRIPT LANGUAGE="JavaScript">
function validar (c) {
      for (var i=0; chk = c.ckb[i]; i++)
    if (chk.checked) return;
    alert("Has de selecionar uno");
    return false;
}

</SCRIPT> 
<body>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>

<table width="100%" border="0" cellspacing="0" cellpadding="0" center>
  <tr>
    <td width="254"><div align="left"><img src="imagenes/top21.jpg" width="254" height="75" /></div></td>
    <td width="" align="right" valign="bottom" class="mainhead Estilo74" title="Consulta Recibo de pago"><div align="center"><center><h3><font face="arial"><font color="#317bae">Consulta de Empleado </font></div></td>
    <td width="300" title="Consulta Recibo de pago"><div align="right"><img src="imagenes/nomsistema.jpg" width="329" height="75" border="0" /></div></td>
	<td width="80" title="Gerencia de Automatización de Servicios"><div align="right"><img src="imagenes/gas.jpg" width="80" height="75" border="0" /></div></td>
  </tr>
  <tr>
    <td colspan="4" style="background-color:#317bae; filter:progid:DXImageTransform.Microsoft.Gradient(endColorstr='#317bae', startColorstr='#ffffff', gradientType='1')">&nbsp;</td>
  </tr>
</table>

<table width="200" border="0" align="right">
          <tr>
            <td><a href="menupri.php"><h4 align="center">Volver</h4></a></td>
          </tr>
</table>
<br />
<br />
<form  method="post" name="formulario" action="siguiente.php?cedula=<?php echo $row_constancia['cedula'];?>" onsubmit="return validar(this);">

<br />
<br />
<br />
<table width="48%" border="0" align="center" class="Estilo9">
<tr>
    <th scope="col" colspan="0" align="center" class="subtitulo2" bgcolor="#317bae"><p align="center"> Elija la Siguente Opcion opci&oacute;n: </p></th>
</tr>
<tr>
    <th width="0%" height="0"scope="row" ><label>
  	<input name="salario" type="radio" value="1"/>
    Sin Salario</label>&nbsp;</th>
    <th width="0%"scope="row" ><label>
  	<input name="salario" type="radio" value="2"/>
  	Con Salario Basico</label>&nbsp;</th>
	<th width="0%"scope="row"><label>
	<?php if (($anio > 1) or(($tipopersonal!=05) and ($tipopersonal!=06) and ($tipopersonal!=07))){ 
	echo "<input name='salario' type='radio' value='3'/>
	Con Salario Integral Estimado";} ?></label>&nbsp;</th>
</tr>
<tr>
	<th height="38" colspan="0" align="center"  bgcolor="#317bae" class="subtitulo2"><p align="center"><strong>Si 										quiere 	con Cesta Tiket Elija la Siguente Opcion opci&oacute;n: </p>
</tr>
<tr>
	<th height="25" colspan="0" align="center" class="subtitulo2"><p align="center"><strong><label>
	<input type="checkbox" name="ticket" value="1"/>
	Con Cesta Tiket</label></th>
</tr>
</table>
<br />
<br />
<table align="center">
<p>
  <th align="center"><label>
    <input type="submit" name="Submit" value="GENERAR REPORTE"/>
    </label></th>
  </p>
 </table>
</body>
</head>
</html>
</form>
  #8 (permalink)  
Antiguo 23/06/2009, 03:55
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: alguien q me ayude con esto

Hola

Prueba a cambiar esto

Código html:
Ver original
  1. <SCRIPT LANGUAGE="JavaScript">
  2. function validar (c) {
  3.       for (var i=0; chk = c.ckb[i]; i++)
  4.     if (chk.checked) return;
  5.     alert("Has de selecionar uno");
  6.     return false;
  7. }
  8.  
  9. </SCRIPT>
  10. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  11. <title>Documento sin t&iacute;tulo</title>

por

Código html:
Ver original
  1. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  2. <title>Documento sin t&iacute;tulo</title>
  3. <SCRIPT LANGUAGE="text/JavaScript">
  4. function validar (c) {
  5.       for (var i=0; chk = c.ckb[i]; i++)
  6.     if (chk.checked) return;
  7.     alert("Has de selecionar uno");
  8.     return false;
  9. }
  10.  
  11. </SCRIPT>
  12. </head>

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #9 (permalink)  
Antiguo 23/06/2009, 06:55
Avatar de darwin_le  
Fecha de Ingreso: mayo-2009
Mensajes: 63
Antigüedad: 15 años
Puntos: 0
Respuesta: alguien q me ayude con esto

hola
alguien mas tiene otra opcion de como hacerlo
  #10 (permalink)  
Antiguo 23/06/2009, 08:12
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: alguien q me ayude con esto

Cita:
Iniciado por darwin_le Ver Mensaje
hola
alguien mas tiene otra opcion de como hacerlo
¿No logras que funcione?
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #11 (permalink)  
Antiguo 23/06/2009, 08:17
Avatar de darwin_le  
Fecha de Ingreso: mayo-2009
Mensajes: 63
Antigüedad: 15 años
Puntos: 0
Respuesta: alguien q me ayude con esto

hola
amigo ya lo aregle pero a hora tengo un problema cuando yo abra esa pantalla el checkbox aparesca false y cuando yo elija el primer radio el checkbox aparesca true ayudamen amigo en esto y se lo sabre agradecer

gracias.
  #12 (permalink)  
Antiguo 23/06/2009, 13:23
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: alguien q me ayude con esto

Hola

Algo como esto

Código javascript:
Ver original
  1. window.onload = function() {
  2. var elem = document.forms[0].elements[0];
  3. elem.onclick = MarcaCheck;
  4. }
  5.  
  6. function MarcaCheck () {
  7. elemento = document.getElementById('ticket');
  8.     if (elemento.type == "checkbox")
  9.     {
  10.     elemento.checked = true
  11.     }
  12. }

Suerte

Cita:
Iniciado por darwin_le Ver Mensaje
hola
amigo ya lo aregle pero a hora tengo un problema cuando yo abra esa pantalla el checkbox aparesca false y cuando yo elija el primer radio el checkbox aparesca true ayudamen amigo en esto y se lo sabre agradecer

gracias.
Que sea un surtido ibérico!!!
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
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 23:18.