zazu Posted February 29, 2016 Share Posted February 29, 2016 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> Quote Link to comment https://forums.phpfreaks.com/topic/300911-showing-a-thank-you-message-after-form-submit/ Share on other sites More sharing options...
Solution requinix Posted February 29, 2016 Solution Share Posted February 29, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/300911-showing-a-thank-you-message-after-form-submit/#findComment-1531588 Share on other sites More sharing options...
zazu Posted February 29, 2016 Author Share Posted February 29, 2016 (edited) 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 February 29, 2016 by zazu Quote Link to comment https://forums.phpfreaks.com/topic/300911-showing-a-thank-you-message-after-form-submit/#findComment-1531592 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.