How to trigger a trigger with jquery?

1

I'm working with a radio button and I can not trigger a trigger. Can anyone help me solve it?

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

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

});

Image of the situation ... if it works out I'll hide this Update Total and send a trigger on it. The html of the button is:

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

Itgoesinsidetheon("change") but does not trigger the action on the button. The goal is, when I click on a radio, it triggers the trigger in Update Total .

    
asked by anonymous 26.09.2016 / 22:33

1 answer

2

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

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

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

Now, I can use trigger :

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

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

DEMO

I hope you have helped.

    
26.09.2016 / 22:45