M
M
M-tc2015-11-10 19:51:05
PHP
M-tc, 2015-11-10 19:51:05

Disappeared form (not popup) after submitting a message. How to fix?

When sending a message, the form itself disappears. Here is the code

$(document).ready(function(){
    $('#contact-form1').submit(function(){
            var subject = $(this).find("#subject1 :selected").text();
            var name = $(this).find("#name1").val();
            var email = $(this).find("#email1").val();
            var message = $(this).find("#message1").val();

            if(!!name && !!email && !!message){
                $.ajax({
                    type: "POST",
                    url: "/email1.php",
                    data: {"subject1": subject, "name1": name,"email1": email, "message1": message},
                    cache: false,
                    success: function(){
                        jQuery('#contact-form1').html("<div id='otpravlen'></div>");  
                        jQuery('#otpravlen').html("<h2>Вопрос отправлен!</h2>")  
                        .append("<p>Скоро мы с вами свяжемся.</p>")  
                        .hide()  
            
                        .fadeIn(1500, function() {  
                        $('#otpravlen').append();  
                        })
      .fadeOut(1500, function() {
       $('#otpravlen').remove();
       }); 
            
                    }
                })
            }
        return false;
    });
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2015-11-10
@M-tc

Because this line

jQuery('#contact-form1').html("<div id='otpravlen'></div>");
you remove everything inside the form and insert a new div in there.
Replace html() with append()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question