Foros del Web » Programando para Internet » Javascript »

validar casilla de verificacion

Estas en el tema de validar casilla de verificacion en el foro de Javascript en Foros del Web. tengo el siguiente código de formulario y no se cómo introducir el script para validar la casilla de verificación. Gracias function Submitir() { var Mensaje; ...
  #1 (permalink)  
Antiguo 18/12/2006, 05:26
 
Fecha de Ingreso: enero-2006
Mensajes: 208
Antigüedad: 18 años, 3 meses
Puntos: 3
validar casilla de verificacion

tengo el siguiente código de formulario y no se cómo introducir el script para validar la casilla de verificación. Gracias


function Submitir()
{

var Mensaje;
Mensaje = '';

if (document.FormularioMolinoBlanco.Nombre.value == '') {
Mensaje = 'Debe indicar su nombre\n';
}
else {
if (document.FormularioMolinoBlanco.Apellidos.value == '') {
Mensaje = "Debe indicar su apellido\n";
}
else {
if (document.FormularioMolinoBlanco.Calle.value == '') {
Mensaje = 'Debe indicar su calle\n';
}
else {
if (document.FormularioMolinoBlanco.Ciudad.value == '') {
Mensaje = 'Debe indicar su ciudad\n';
}
else {
if (document.FormularioMolinoBlanco.Pais.value == '') {
Mensaje = 'Debe indicar el país\n';
}
else {
if (document.FormularioMolinoBlanco.llegada.value == '') {
Mensaje = 'Debe indicar la llegada\n';
}
else {
if (document.FormularioMolinoBlanco.salida.value == '') {
Mensaje = 'Debe indicar la salida\n';
}
else {
if (document.FormularioMolinoBlanco.email2.value == '') {
Mensaje = 'Debe indicar su email\n';
}
else {
if (document.FormularioMolinoBlanco.email2.value.inde xOf("@")== -1) {
Mensaje = 'Su dirección email es erronea\n';
}
}
}
}
}
}
}
}
}

if (Mensaje == '') {
document.FormularioMolinoBlanco.submit();
}else {
alert(Mensaje);
}


}
  #2 (permalink)  
Antiguo 18/12/2006, 06:16
 
Fecha de Ingreso: enero-2005
Ubicación: Barcelona
Mensajes: 384
Antigüedad: 19 años, 3 meses
Puntos: 0
Re: validar casilla de verificacion

Para verificar si un checkbox está marcdo me parece que es de esta forma:
Código HTML:
if(document.FormularioMolinoBlanco.NOMBRE_CHECKBOX.[B].checked == true[/B])
Prueba con eso, a ver si te sirve.
__________________
m!ketrix
CINE25 - Red Social de Cine
byinspiroh
  #3 (permalink)  
Antiguo 18/12/2006, 10:20
 
Fecha de Ingreso: enero-2006
Mensajes: 208
Antigüedad: 18 años, 3 meses
Puntos: 3
Re: validar casilla de verificacion

Pues no me sirvió :((... no funciona..
  #4 (permalink)  
Antiguo 18/12/2006, 10:26
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Re: validar casilla de verificacion

Hola hema

En el código de miketrix_esp se han colado unas etiquetas para poner el código en negrita. Ponlo así:

if(document.FormularioMolinoBlanco.NOMBRE_CHECKBOX .checked)

Espero que te sirva. Saludos,
  #5 (permalink)  
Antiguo 18/12/2006, 18:30
 
Fecha de Ingreso: enero-2006
Mensajes: 208
Antigüedad: 18 años, 3 meses
Puntos: 3
Re: validar casilla de verificacion

todavía no me funciona....tendrá que ver con el 'value'? o es q no lo estaré incluyendo bien en el código????
  #6 (permalink)  
Antiguo 19/12/2006, 04:43
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Re: validar casilla de verificacion

Hola hema

Pon el código del formulario para poder hacer alguna prueba.

Saludos,
  #7 (permalink)  
Antiguo 19/12/2006, 08:20
 
Fecha de Ingreso: enero-2005
Ubicación: Barcelona
Mensajes: 384
Antigüedad: 19 años, 3 meses
Puntos: 0
Re: validar casilla de verificacion

Cita:
Iniciado por JavierB Ver Mensaje
Hola hema

En el código de miketrix_esp se han colado unas etiquetas para poner el código en negrita. Ponlo así:

if(document.FormularioMolinoBlanco.NOMBRE_CHECKBOX .checked)

Espero que te sirva. Saludos,
Jaja osti JavierB, no me había fijao xD.

hema, enseñanos tu codigo para ver como lo utilizas exactamente.
__________________
m!ketrix
CINE25 - Red Social de Cine
byinspiroh
  #8 (permalink)  
Antiguo 19/12/2006, 10:30
 
Fecha de Ingreso: enero-2006
Mensajes: 208
Antigüedad: 18 años, 3 meses
Puntos: 3
Re: validar casilla de verificacion

Lo mando en dos respuestas ya que no me deja pegar todo el código.
Esto va en el head

<head>
<title>SISTEMA DE RESERVAS </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
//-->
</script>
<script language="JavaScript" type="text/JavaScript">
<!--


// **********************



function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}



function Submitir()
{

var Mensaje;
Mensaje = '';

if (document.FormularioMolinoBlanco.Nombre.value == '') {
Mensaje = 'Debe indicar su nombre\n';
}
else {
if (document.FormularioMolinoBlanco.Apellidos.value == '') {
Mensaje = "Debe indicar su apellido\n";
}
else {
if (document.FormularioMolinoBlanco.Calle.value == '') {
Mensaje = 'Debe indicar su calle\n';
}
else {
if (document.FormularioMolinoBlanco.Ciudad.value == '') {
Mensaje = 'Debe indicar su ciudad\n';
}
else {
if (document.FormularioMolinoBlanco.Pais.value == '') {
Mensaje = 'Debe indicar el país\n';
}
else {
if (document.FormularioMolinoBlanco.llegada.value == '') {
Mensaje = 'Debe indicar la llegada\n';
}
else {
if (document.FormularioMolinoBlanco.salida.value == '') {
Mensaje = 'Debe indicar la salida\n';
}
else {
if (document.FormularioMolinoBlanco.email2.value == '') {
Mensaje = 'Debe indicar su email\n';
}
else {
if (document.FormularioMolinoBlanco.email2.value.inde xOf("@")== -1) {
Mensaje = 'Su dirección email es erronea\n';

}
else{
if(document.FormularioMolinoBlanco.agree.checked == true){
Mensaje ='Acepte las condiciones\n';
}
}

}


}
}
}
}
}
}
}

if (Mensaje == '') {
document.FormularioMolinoBlanco.submit();
}else {
alert(Mensaje);
}


}

//-->
</script>


<style type="text/css">
<!--
body {
background-color: #FFFFFF;
}
.Estilo2 {color: #000066}
.Estilo6 {
font-weight: bold;
font-size: 11px;
color: #003D01;
}
a:link {
color: #FFFFFF;
}
a:visited {
color: #FFFFFF;
}
.Estilo27 {color: #003D01; font-size: 11px; font-style: italic; }
.Estilo29 {font-weight: bold; color: #000066; font-style: italic; }
.Estilo30 {font-size: 11px; font-weight: bold;}
.Estilo36 {font-weight: bold; font-size: 11px; color: #000066; }
.Estilo37 {color: #003D01; font-style: italic; }
.Estilo39 {font-weight: bold; font-size: 11px; font-style: italic;}
-->
</style>





<!-- calendar stylesheet -->
<link rel="stylesheet" type="text/css" media="all" href="reserva/calendar-green.css" title="win2k-cold-1" />

<!-- main calendar program -->
<script type="text/javascript" src="reserva/calendar.js"></script>

<!-- language for the calendar -->
<script type="text/javascript" src="reserva/lang/calendar-es.js"></script>

<!-- the following script defines the Calendar.setup helper function, which makes
adding a calendar a matter of 1 or 2 lines of code. -->
<script type="text/javascript" src="reserva/calendar-setup.js"></script>


<style type="text/css">
<!--
a:hover {
color: #FFFFFF;
}
a:active {
color: #FFFFFF;
}
.Estilo42 {color: #003D01}
-->
</style>
<link href="_not/estilos.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.Estilo43 {
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
color: #000066;
}
-->
</style>

</head>
  #9 (permalink)  
Antiguo 19/12/2006, 10:36
 
Fecha de Ingreso: enero-2006
Mensajes: 208
Antigüedad: 18 años, 3 meses
Puntos: 3
Re: validar casilla de verificacion

no me deja poner el resto del formulario...

pero la función se llama con el botón enviar:

<input name=B1 type=button value="Enviar" onClick="Submitir();">
  #10 (permalink)  
Antiguo 03/04/2009, 04:01
 
Fecha de Ingreso: abril-2009
Mensajes: 3
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: validar casilla de verificacion

JavierB

llevo horas intentando hacer un formulario y que me valide una casilla de verificacion, cuando por fin logre hacer que me lo valide, siguiendo tus cosejos claro. Pero ahora me salta otro problema mucho mas grave "el formulario no envia" utilizo este script

//valido el checked
if (document.fvalida.acepto.checked == 0)
alert("Debe aceptar los terminos y condiciones.")
return false;
}


el codigo de la casilla de verificacion es este


<input name="acepto" type="checkbox" id="acepto" value="checkbox" />


y el formulario es este.


<form action="send.php#rescon" method="post" name="fvalida" target="_self" id="fvalida" onsubmit="return validar();">

bueno esos son solo partes de los codigos, espero me puedan ayudar con esos datos porque ya me estoy volviendo loco y nesecito terminarlo pronto.

gracias.
  #11 (permalink)  
Antiguo 03/04/2009, 04:05
 
Fecha de Ingreso: abril-2009
Mensajes: 3
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: validar casilla de verificacion

Bueno aquí dejo mi formulario completo para que lo puedan analizar mejor. por que es un poco urgente.

<SCRIPT LANGUAJE="JavaScript">

function validar(){
//valido el nombre
if (document.fvalida.nombre.value.length==0){
alert("Tiene que escribir su Nombre y Apellido")
document.fvalida.nombre.focus()
return false;
}
//valido el dominio
if (document.fvalida.mensaje.value.length==0){
alert("Tiene que ingresar el dominio que desea registrar")
document.fvalida.mensaje.focus()
return false;
}
//valido la direccion
if (document.fvalida.direccion.value.length==0){
alert("Tiene que escribir su direccion")
document.fvalida.direccion.focus()
return false;
}
//valido la ciudad
if (document.fvalida.ciudad.value.length==0){
alert("Tiene que escribir su Ciudad")
document.fvalida.ciudad.focus()
return false;
}
//valido el departamento
if (document.fvalida.departamento.value.length==0){
alert("Tiene que escribir su Departamento")
document.fvalida.departamento.focus()
return false;
}
//valido el e-mail
if (document.fvalida.mail.value.length==0){
alert("Tiene que escribir su e-mail")
document.fvalida.mail.focus()
return false;
}
//valido el codigo postal
if (document.fvalida.postal.value.length==0){
alert("Tiene que escribir el Codigo Postal")
document.fvalida.postal.focus()
return false;
}
//valido el telefono
if (document.fvalida.telefono.value.length==0){
alert("Tiene que escribir su numero de telenofo o celular")
document.fvalida.telefono.focus()
return false;
}
//valido el plan
if (document.fvalida.plan.selectedIndex==0){
alert("Debe seleccionar un plan de hosting.")
document.fvalida.plan.focus()
return false;
}
//valido el checked
if (document.fvalida.acepto.checked == 0)
alert("Debe aceptar los terminos y condiciones.")
return false;
}

</SCRIPT>

este es el script completo.
  #12 (permalink)  
Antiguo 03/04/2009, 04:13
 
Fecha de Ingreso: abril-2009
Mensajes: 3
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: validar casilla de verificacion

y aquí el formulario completo.
espero su ayuda.
gracias.

<body>
<form action="send.php#rescon" method="post" name="fvalida" target="_self" id="fvalida" onsubmit="return validar();">
<table width="470" border="0" align="center" cellpadding="0" cellspacing="4">
<tr>
<td width="184">&nbsp;</td>
<td width="271">&nbsp;</td>
</tr>
<tr>
<td><div align="right"><span class="Estilo6">Empresa</span>:</div></td>
<td><input name="empresa" type="text" id="empresa" size="30" />
<span class="Estilo1">--*<span class="Estilo4">Opcional</span></span></td>
</tr>
<tr>
<td>&nbsp;</td>
<td height="35" bgcolor="#E2E7F5" class="Estilo4">*No es obligatorio tener una empresa para tener su<br />
propio dominio. </td>
</tr>
<tr>
<td><div align="right" class="Estilo6">Dominio a Registrar:</div></td>
<td><input type="text" name="mensaje" id="mensaje" size="30" /></td>
</tr>

<tr>
<td>&nbsp;</td>
<td height="49" bgcolor="#E2E7F5" class="Estilo4">* <br />
*No se olvide de agregar la extencion (.com .net .org<br />
.info .biz)</td>
</tr>

<tr>
<td><div align="right" class="Estilo6">Nombre y Apellido:</div></td>
<td><input name="nombre" type="text" id="nombre" size="43" /></td>
</tr>
<tr>
<td><div align="right" class="Estilo6"><span class="Estilo7">Dirección</span>:</div></td>
<td><input name="direccion" type="text" id="direccion" size="43" /></td>
</tr>
<tr>
<td><div align="right" class="Estilo6">Ciudad:</div></td>
<td><input name="ciudad" type="text" id="ciudad" size="30" /></td>
</tr>
<tr>
<td><div align="right" class="Estilo6">Departamento:</div></td>
<td><input name="departamento" type="text" id="departamento" size="30" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><div align="right" class="Estilo6">E-mail:</div></td>
<td><input name="mail" type="text" id="mail" size="43" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td height="25" bgcolor="#E2E7F5" class="Estilo4">*Asegurese de ingresar correctamente su e-mail </td>
</tr>
<tr>
<td><div align="right" class="Estilo6">Codigo Postal:</div></td>
<td><input name="postal" type="text" id="postal" size="25" /></td>
</tr>
<tr>
<td><div align="right" class="Estilo6">Teléfono:</div></td>
<td><input name="telefono" type="text" id="telefono" size="25" /></td>
</tr>
<tr>
<td><div align="right" class="Estilo6">Fax:</div></td>
<td><input name="fax" type="text" id="fax" size="25" />
<span class="Estilo1">--<span class="Estilo4">Opcional</span></span></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td class="Estilo6">Plan de hosting:</td>
<td><select name="plan" id="plan">
<option>Seleccionar una opcion</option>
<option>Ningun Plan</option>
<option>Plan Inicial</option>
<option>Plan Basico</option>
<option>Plan Avanzado</option>
<option>Plan Profesional</option>
<option>Plan Premium</option>
<option>Plan Corporativo</option>
</select></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><label class="Estilo6">Terminos y Condiciones:</label></td>
<td><p><span class="Estilo4">
<input name="acepto" type="checkbox" id="acepto" value="checkbox" />
SI acepto los terminos y condiciones</span></p>
/td>
</tr>
</table>
<label><br />
</label>
<p>
<label></label>
<label></label>
<label></label>
<label></label>
</p>
<p align="center">
<input name="onSubmit" type="submit" id="onSubmit" value="Enviar Solicitud &raquo;" />
<span class="Estilo8">--</span>
<input type="reset" name="Submit" value="Limpiar formulario" />
</p>
</form>
</body>
</html>
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 17:12.