Hola
Tarde, pero he entendido cual es el problemas
Prueba así
Código javascript
:
Ver original<!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" lang="es">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Formulario</title>
<script type="text/javascript">
function eliminaEspacios(cadena) {
return (cadena.replace(/(^\s*)|(\s*$)/g,""));
}
function checkFields(c) {
missinginfo = "";
// Primer paso: Obtener el rut que ingreso el usuario
var nameCompleto = c.nombre.value;
// Eliminamos los caracteres raros, espacios, puntos, guiones.
// Pasamos a minusculas, y separamos el rut y el digito verificador
nameCompleto = nameCompleto.replace(/[ \.-]/g, "");
nameCompleto = nameCompleto.toLowerCase();
var nombre = nameCompleto.substring(0, nameCompleto.length - 1)
alert ("Campo con espacios al principio ("+c.nombre.value+") y al final");
var nombre1=eliminaEspacios(nombre);
alert ("Campo sin espacios al principio ("+nombre1+") y al final");
var mesaje1=eliminaEspacios(c.mensaje.value);
var email1=eliminaEspacios(c.email.value);
if (nombre1=="") {
missinginfo += "\n - Campo Nombre";
}
if (mesaje1=="") {
missinginfo += "\n - Campo Mensaje";
}
if ((email1 == "") ||
(c.email.value.indexOf('@') == -1) ||
(c.email.value.indexOf('.') == -1)) {
missinginfo += "\n - Campo E-mail";
}
if (missinginfo != "") {
missinginfo ="Los siguentes campos del formulario \n no han sido completados o tienen errores: \n" +
"" +
missinginfo + "" +
"\n ";
alert(missinginfo);
return false;
}
else return true;
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="enviar.php" onsubmit="return checkFields(this);">
<p>
<select name="correo" id="correo" style="width:100px" >
<option selected="selected" value="prensa" > Prensa </option>
<option value="ventas"> Ventas </option>
</select>
</p>
<p> Nombre:<br />
<label>
<input name="nombre" type="text" id="nombre" />
</label>
<br />
Telefono:<br />
<input name="telefono" type="text" id="telefono" />
<br />
Email:<br />
<input name="email" type="text" id="email" />
<br />
Mensaje:<br />
<textarea name="mensaje" id="mensaje" rows="" cols=""></textarea>
<br />
<label>
<input type="submit" name="Submit" value="Enviar Formulario" />
</label>
</p>
</form>
</body>
</html>
Suerte