Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/12/2010, 08:20
fupinet
 
Fecha de Ingreso: julio-2009
Mensajes: 100
Antigüedad: 14 años, 10 meses
Puntos: 4
Exclamación Form de Contacto

Buenas a todos tengo el siguiente codigo de un formulario de contacto con validacion en javascript.
Siempre me ha funcionado pero ahora quiero añadir una cosa y no lo consigo hacer.
El codigo muestra un aviso cuando el valor es igual a cero, pero si le pongo un valor inicial,
¿que tengo que incluir en el codigo para que cuando sea igual al valor iniciar se muestre tambien el aviso ?para que asi no se envie el formulario con las variables nombre.apellidos....sino obligar al usuario a escribir a cada campo.

y por ultimo seria de lujo si alguien sabe como poner a cero el valor cuando hacemos click en el input de textos y no tener que borrar el valor inicial.

mi codigo html y javascript es el siguiente:
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>formulario</title>
    <script type="text/javascript">
function valida_envia(){ 
	if (!document.registro.email.value.match("@"))
{ alert("Debe ingresar el Email o verifique que sea correcto.")
document.registro.email.focus()
return 0;
} 

	if (document.registro.nombre.value.length==0) {
       alert("Tiene que escribir su nombre")
       document.registro.nombre.focus()
       return 0;
    } 
if (document.registro.apellidos.value.length==0) {
       alert("Tiene que escribir sus apellidos")
       document.registro.apellidos.focus()
       return 0;
    } 
	if (document.registro.tel.value.length==0) {
       alert("Tiene que escribir su teléfono")
       document.registro.tel.focus()
       return 0;
    } 
	if (document.registro.comentario.value.length==0) {
       alert("Tiene que escribir un comentario")
       document.registro.comentario.focus()
       return 0;
    } 
	document.registro.submit(); 
	
	}
	</script>

</head>

<body>

<form id="registro" name="registro" method="post" action="registro.php">
<table width="228" height="220" border="0" align="center" cellpadding="5" cellspacing="0" class="tbmain">
  <tr>
    <td height="25" colspan="2" >&nbsp;</td>
    </tr>
  <tr>
    <td height="25" colspan="2"  style="font-size:14px; font-weight:bold;">Contacto</td>
    </tr>
  <tr>
    <td width="144" height="34" ><input name="nombre" type="text" id="nombre"  onblur="validate(this,'Required')" value="nombre" size="26" maxsize="100" /></td>
    <td width="164" >
      <input name="apellidos"  type="text" id="apellidos"  onblur="validate(this,'Required')" value="apellidos" size="26"  maxlength="100" maxsize="100" />
   </td>
    </tr>
  <tr>
    <td height="34" ><input name="tel" type="text" id="tel"  onblur="validate(this,'Required')" value="tel" size="26" maxsize="100" /></td>
    <td >
      <input name="email"  type="text" id="email" style=" padding-left: 10px;" onblur="validate(this,'Required')" value="email address" size="26"  maxlength="100" maxsize="100" />
  </td>
  </tr>
  <tr>
    <td height="34" colspan="2" style="padding-right:7px;">
      <textarea name="comentario" id="comentario" cols="57" rows="5"  onblur="validate(this,'Required')">comentario</textarea></td>
  </tr>
  <tr>
      </tr>
  <tr>
    <td height="34" colspan="2" style="padding-right:7px;"> <input type="button" name="Submit" class="btn"  value="enviar&gt;"  onclick="valida_envia()"/></td>
    </tr>
</table>
</form>
</body>
</html> 
Un saludo y Muchas Gracias