Jump to content

Showing a thank you message after form submit


zazu
Go to solution Solved by requinix,

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>
Link to comment
Share on other sites

  • Solution

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.

Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.