How to fire a Rigger with jquery?

Asked

Viewed 489 times

1

I’m working with radio type button and I can’t fire a Rigger. Can someone help me solve?

$("input[name='estimate_method']").on('change', function() {

    $(this).prop("checked", true);
    $("input[name='do']").trigger("click");

});

Picture of the situation ... if it works I’ll hide this Update Total and send a Trigger on top of it. The html button is:

<button type="submit" class="button" name="do" value="Atualizar Total">            
     <span>
         <span>Atualizar Total</span>
     </span>
</button> 

inserir a descrição da imagem aqui

He goes inside the on("change") but not trigger the action on the button. The goal is, the moment I click a radio, it fire the Trigger on the Update Total.

1 answer

2


In order to use the trigger jquery you must previously assign a function to the particular event you want to fire, for example:

At the event click of the button use a .preventDefault() and then use the function .submit() in the form, so the button has the same function but now this is declared and the event can be recognized by jquery:

$('form button').click(function(e){
    e.preventDefault();
    $('form').submit();
})

Now I can use the Trigger:

$('form input:radio').on('change', function(){
    $('form button').trigger('click')
});

If you just want to submit the form, can use the .submit() that I used above.

DEMO

I hope it helped.

  • 1

    You have helped me!! Thank you.

Browser other questions tagged

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