Jump to content
Sign in to follow this  
zazu

Showing a thank you message after form submit

Recommended Posts

Hi guys. I have a Bootstrap modal that opens on click. Inside is a form with 4 fields. Now i want after the form is submited to show below the submit button a thank yo message, but instead of that the form closes and the page is beeing refreshed. I've manage to do some javascript to stop the form of beeing refreshed but now i want to know how can i make the thank you div to get showed below the submit button.

<script>
        $(function () {
    var frm = $('#participa-modal');
    frm.submit(function (ev) {
        $.ajax({
            type: frm.attr('method'),
            url: frm.attr('action'),
            data: frm.serialize(),
            success: function (data) {
            $(".alert-success").html(data);
            location.reload();
            }
        });
    ev.preventDefault();
    });
});
        </script>

Share this post


Link to post
Share on other sites

The page is being refreshed because of that location.reload(), so if you don't want that to happen then don't put that code in there.

 

Is the .alert-success (which you should probably put an ID on rather than relying on just the class name) visible? As in it doesn't have a display:none or something? If it is, and probably should be, then you need to .show() it too.

Share this post


Link to post
Share on other sites

The page is being refreshed because of that location.reload(), so if you don't want that to happen then don't put that code in there.

 

Is the .alert-success (which you should probably put an ID on rather than relying on just the class name) visible? As in it doesn't have a display:none or something? If it is, and probably should be, then you need to .show() it too.

<script>
        $(function () {
    var frm = $('#inscriete-modal');
    frm.submit(function (ev) {
        $.ajax({
            type: frm.attr('method'),
            url: frm.attr('action'),
            data: frm.serialize(),
            success: function (data) {
            $("#form-inscriere").show(data);
            setTimeout(function(){location.reload();},3000);
            }
        });
    ev.preventDefault();
    });
});
        </script>
Edited by zazu

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.