0
I need to open a modal after a Submit happens on a certain button, I was wondering if you have any event for this, something like post-Submit.
0
I need to open a modal after a Submit happens on a certain button, I was wondering if you have any event for this, something like post-Submit.
2
Apparently you’re using jQuery there is only use the Event.preventDefault()
something like
$('#meuform').on('submit', function(event){
event.preventDefault();
//abre a modal aqui
});
That will stop the action default
of the event, in this case, sending(submit
) form, and will allow open your modal.
As a side effect sending the data will have to be done via ajax.
There is a "gambiarra" that depending on what you need can work. It consists of giving a return false
instead of using the preventDefault()
, usually use to do some sort of validation via js before sending.
$('#meuform').on('submit', function(event){
if(!validaForm()){
//abre a modal aqui
return false;
}
});
I wanted to merge the two things, I need the Submit without giving a refresh on the page, if possible without using ajax.
The purpose of Submit is precisely to send/write to an address, specified in the attribute action
, the form data, when it does not define a action
browser assume it is the current page, so refresh it. So no, there is, as far as I know, a refresh-free Submit of the page.
I understand your logic.
give a new look I edited the answer, depending on what you need can give a return false
, I don’t know if that’s the case but it will...
1
One option is to prevent the page from being reloaded using event.preventDefault
:
$( "#form" ).submit(function( event ) {
event.preventDefault();
$( "#dialog" ).show();
});
Quaseee dude, the problem that now Submit with the new Id does not happen, I think only with ajax same right.
Yes, it is the most suitable. You can do the POST by ajax and serialize the data in sending.
Browser other questions tagged php javascript jquery
You are not signed in. Login or sign up in order to post.
When Ubmit does the page it does refresh right?
– Miguel
Aham, that refresh is not letting my modal open.
– Roberto Albino