Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/02/2011, 08:25
Avatar de ale_dla
ale_dla
 
Fecha de Ingreso: abril-2009
Ubicación: Buenos Aires, Argentina
Mensajes: 189
Antigüedad: 15 años, 9 meses
Puntos: 3
Validar y no borrar lo que ya estaba escrito en otro campo

HOla!
Tengo un form en html en el cual tiene que validar.hace la validacion bien pero si yo ingrese texto en otro campo y cuando me muestra un error me borra todo.
COmo hago para que eso no pase?
Este es mi codigo:
Código PHP:
<html>
<
head>
<
title>Formulario</title>
<
script type="text/javascript">
function 
validarEmail(email) {
var 
email.value;
var 
filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+.[A-Za-z0-9_.]+[A-za-z]$/;
if (
a.length == )
return 
true;
if (
filter.test(a))
return 
true;
else
alert("Porfavor, debe ingresar una dirección de correo válida");
email.focus();
return 
false;
}


    function 
validar_formulario() { 
        if (
document.formulario.nombre.value=="") {
            
alert("Escriba su nombre."); 
            
document.formulario.nombre.focus(); 
            return (
false); 
        } 
        if (
document.formulario.apellido.value==""){
            
alert("Escriba su apellido.");
            
document.formulario.apellido.focus();
            return (
false);
        }
        if (
document.formulario.direccion.value==""){
            
alert("Escriba su direccion.");
            
document.formulario.direccion.focus();
            return (
false);
        }
        if (
document.formulario.email.value=="") { 
            
alert("Escriba su email"); 
            
email.focus(); 
            return 
false
        } 
        if (
document.formulario.telefono.value==""){
            
alert("Escriba su numero de telefono.");
            
telefono.focus();
            return 
false;
        }
        
        
//el formulario se envia
    
alert("Muchas gracias por enviar el formulario");
    
document.formulario.submit(); 
}
</script>
</head>
<body>
<form onsubmit="validar_formulario()" name="formulario" method="post"/>
<table border="0" cellspacing="2" cellpadding="1" align="center"/>

<tr>
    <td>Nombre</td>
    <td><input type="text" name="nombre"/></td>
</tr>
<tr>
    <td>Apellido</td>
    <td><input type="text" name="apellido"/></td>
</tr>
<tr>
    <td>Direccion</td>
    <td><input type="text" name="direccion"/></td>
</tr>
<tr>
    <td>E-mail</td>
    <td><input type="text" name="email" onClick="validarEmail(this)"/></td>
</tr>
<tr>
    <td>Telefono</td>
    <td><input type="text" name="telefono"/></td>
</tr>
<tr>
    <td></td>
    <td><input type="submit" name="enviar" value="Enviar"/></td>
</tr>
</table>
</form>
</body>
</html> 
Quien pueda ayudarme se los agradezco,!
Saludos