Ver Mensaje Individual
  #3 (permalink)  
Antiguo 17/08/2009, 20:07
Avatar de deirdre
deirdre
 
Fecha de Ingreso: mayo-2009
Mensajes: 690
Antigüedad: 14 años, 11 meses
Puntos: 45
Respuesta: como decir q una pregunta no fue contestada en el formulario

Hola apenha15

Si quieres un sistema para validar que en los campos de un formulario se haya escrito y que el campo del email contenga una @ y . (punto) y que no cargue una pesada librería sólo para eso, aquí te adjunto un prototipo que funciona de esa forma y es muy liviano de peso:

Código HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Validacion sencilla de campos de formulario</title>

<script type="text/javascript">
function validate_email(field,alerttxt)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}

function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}

function validate_form(thisform)
{
with (thisform)
  {
  if (validate_required(nombre,"Por favor, escriba su nombre")==false)
  {nombre.focus();return false;}

  if (validate_email(email,"Por favor, escriba su email")==false)
    {email.focus();return false;}

  if (validate_required(profesion,"Por favor, escriba su profesion")==false)
  {profesion.focus();return false;}
  
  if (validate_required(domicilio,"Por favor, escriba su domicilio")==false)
  {domicilio.focus();return false;}

  if (validate_required(mensaje,"Por favor, escriba su mensaje")==false)
  {mensaje.focus();return false;}
  
  }
}
</script>
<style type="text/css">
#formulario {
	width: 340px;
	height: 320px;
	text-align: left;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
	background-color:#e1e1e1;
	padding: 8px;
	border: 1px solid #484848;
}
.caja {
	width: 310px;
	text-align: left;
}
input {
	width: 300px;
}
textarea {
	width: 300px;
}
.boton {
	width: 80px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
	*margin-left: -20px; /* necesario para ie */
}
li {
	width: 300px;
	list-style-type: none;
	margin-left: -20px;
	margin-top: 8px;
}
label {
	float: left;
	clear: both
}
</style>
</head>

<body>
<div id="formulario">
	<form action="enviar.php" onsubmit="return validate_form(this)" method="post" class="caja">
	<ul>
		<li><label>Nombre:</label> <input type="text" name="nombre" size="30" /></li>
		<li><label>Email:</label> <input type="text" name="email" size="30" /></li>
		<li><label>Profesion:</label> <input type="text" name="profesion" size="30" /></li>
		<li><label>Domicilio:</label> <input type="text" name="domicilio" size="30" /></li>
		<li><label>Mensaje:</label> <textarea name="mensaje" cols="20" rows="4"></textarea></li>
		<li><input type="submit" value="Enviar" class="boton" /></li>
	</ul>
	</form>
</div>
</body>

</html> 
Comenta algo.

Bye