Programación Web y Scripting > JavaScript
Mostrar imagen "mensaje enviado" cuando el mensaje es enviado?
Eclypse:
Alguien que me ayude porfavor necesito resolver eso :(
caperutxa:
Prueba a quitar la función "externa" y ponerla en la validación. Algo como esto
if(validation==true){
$.post(url, data, function() {
$('#submit').fadeTo("slow", 0.1);
$('#msjEnviado').fadeIn("normal");
$('#formulario')[0].reset();
document.getElementById('#msjEnviado').style.display = 'block';
});
PD: Revisa la sintaxis y la coherencia con tu algortimo, ya que el que habías posteado no lo era.
Eclypse:
Bueno ya lo solucione me gustaria saber si ahi algun error de codigo? por el momento lo unico que me falla es que no recibo ningun mensaje a mi correo cuando envio.
--- Código: Javascript ---$(document).ready(function(){ $("#submit").click(function() { var nombre = $("#nombre").val(); email = $("#email").val(); validacion_email = /^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/; telefono = $("#telefono").val(); asunto = $("#asunto").val(); mensaje = $("#mensaje").val(); if (nombre == "") { $("#nombre").focus().after("<span class='error'>Ingrese su nombre</span>"); $("#nombre").keyup(function(){ if( $(this).val() != "" ){ $(".error").fadeOut(); return false; } }); return false; }else if(email == "" || !validacion_email.test(email)){ $("#email").focus().after("<span class='error'>Ingrese un email correcto</span>"); $("#email").keyup(function(){ if( $(this).val() != "" && validacion_email.test($(this).val())){ $(".error").fadeOut(); return false; } }); return false; }else if(mensaje == ""){ $("#mensaje").focus().after("<span class='error'>Ingrese un mensaje</span>"); $("#mensaje").keyup(function(){ if( $(this).val() != "" ){ $(".error").fadeOut(); return false; } }); return false; }else{ var datos = 'nombre='+ nombre + '&email=' + email + '&telefono=' + telefono + '&asunto=' + asunto + '&mensaje=' + mensaje; $.ajax({ type: "POST", url: "contacto.php", data: datos, success: function() { $('.msg').text('Mensaje enviado!').addClass('msg_ok').animate({ 'left' : '400px' }, 300); $('#submit').fadeOut("slow"); $('#formulario')[0].reset(); }, error: function() { $('.msg').text('Hubo un error!').addClass('msg_error').animate({ 'left' : '400px' }, 300); } }); return false; } });});
Eclypse:
Lo he modificado y mejorado :D
--- Código: Javascript ---$(document).ready(function(){ $("#submit").click(function() { var nombre = $("#nombre").val(); email = $("#email").val(); validacion_email = /^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/; telefono = $("#telefono").val(); asunto = $("#asunto").val(); mensaje = $("#mensaje").val(); if (nombre == "") { $("#nombre").focus().after("<span class='error'>Ingrese su nombre</span>"); $("#nombre").keyup(function(){ if( $(this).val() != "" ){ $(".error").fadeOut(); return false; } }); return false; }else if(email == "" || !validacion_email.test(email)){ $("#email").focus().after("<span class='error'>Ingrese un email correcto</span>"); $("#email").keyup(function(){ if( $(this).val() != "" && !validacion_email.test($(this).val())){ $(".error").fadeOut(); return false; } }); return false; }else if(telefono == ""){ $("#telefono").focus().after("<span class='error'>Ingrese un telefono</span>"); $("#telefono").keyup(function(){ if( $(this).val() != "" ){ $(".error").fadeOut(); return false; } }); return false; }else if(asunto == ""){ $("#asunto").focus().after("<span class='error'>Ingrese un asunto</span>"); $("#asunto").keyup(function(){ if( $(this).val() != "" ){ $(".error").fadeOut(); return false; } }); return false; }else if(mensaje == ""){ $("#mensaje").focus().after("<span class='error'>Ingrese un mensaje</span>"); $("#mensaje").keyup(function(){ if( $(this).val() != "" ){ $(".error").fadeOut(); return false; } }); return false; }else{ var datos = 'nombre='+ nombre + '&email=' + email + '&telefono=' + telefono + '&asunto=' + asunto + '&mensaje=' + mensaje; $.ajax({ type: "POST", url: "contacto.php", data: datos, success: function() { $('#formulario #accept').fadeIn("normal"); $('#submit').fadeOut("slow"); $('#formulario')[0].reset(); }, error: function() { $('#formulario #error').fadeIn("normal"); } }); return false; } });});
Navegación
[*] Página Anterior
Ir a la versión completa