martes, 21 de marzo de 2017

Formulario que nos pide nombre, dirección y telefono y nos lo envia por correo electronico

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Validación de un formulario</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
function valida(f) {
    var ok = true;
    var msg = "Debes escribir algo en los campos:\n";//\n es retorno de linia
    if(f.txtNombre.value == ""){
        msg += "- Nombre\n";
        ok = false;
    }
   
    if(f.txtDireccion.value == ""){
        msg += "- Dirección\n";
        ok = false;
    }
    var patron=/^[0-9]{9}$/;
    if(f.txtTelefono.value == "" || (!patron.test(f.txtTelefono.value))){
        msg += "- Teléfono\n";
        ok = false;
        }
       
   
   
    //Salida
    if(ok == false)
        alert(msg);
    return ok;
}
</script>
</head>
<body>
<form name="form1" id="form1" action="#" method="post" onsubmit="return valida(this)">   
<table border="0">
    <tr>
        <td><label for="txtNombre">Nombre(*):</label></td>
        <td><input type="text" name="txtNombre" id="txtNombre" size="20"/></td>
    </tr>
    <tr>
        <td><label for="txtDireccion">Dirección(*):</label></td>
        <td><input type="text" name="txtDireccion" id="txtDireccion" size="20"/></td>
    </tr>
    <tr>
        <td><label for="txtTelefono">Teléfono(*):</label></td>
        <td><input type="text" name="txtTelefono" id="txtTelefono" /></td>
    </tr>
</table>
<input type="submit" name="btnEnviar" id="btnEnviar" value="Enviar >>"/></br>
<input type="reset" value="Borrar" />
</form>
</body>
</html>

No hay comentarios:

Publicar un comentario