The Submit event doesn’t work when I try to register

Asked

Viewed 224 times

0

Guys I’m having a problem in my jquery, the code below shows the moment that I register the Submit event by clicking on the button

$("#quero-me-identificar").click(function () {
   if($(this).is(":checked")){
     $("#painel-dados-usuario").show();

     $("#login-card").show();
     abrirLogin();
  }
});


function abrirLogin() {

$("#loginForm").submit(function (event) {
    console.log("sdf");
    event.preventDefault();
});


}

My html code

<form id="loginForm" method="post" action="">
   <button id="entrar" class="botao-login" style="float: left;margin-right: 15px">
    Entrar
   </button>
</form>

The problem that occurs is that the action does not enter the event Submit, I’ve already done one $("#loginForm").length and he can identify that there is a form

I’ve tried other ways and I can’t get anyone to help me

  • To make the Submit event occur via javascript you need to give a Trigger on it $("#loginForm"). Trigger('Submit');

  • Actually it doesn’t need, um $("#loginForm").submit(); would suffice, but he’s giving a event.preventDefault(); then he’ll need to make one $("#loginForm").unbind('submit').submit();

  • 'Cause I did it that way and it worked when I click the button being the button type but when I click the button like Ubmit to give the Ubmit it does not fall in the event that I registered understood.

  • You want to remove the event.preventDefault();?

  • I didn’t want it to continue, I wanted it to enter the Submit event that I registered and then stop with Event.preventDefault();

1 answer

0

How are you using event.preventDefault(); in his $("#loginForm")

you will need to use a .unbind() to make the Submit on the location you want

$("#loginForm").unbind('submit').submit();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.