Calling event inside another jquery event

Asked

Viewed 422 times

0

I would like to call an event within another event..

Would be the Event B within the else if ($(this).val() == "C"), of Event A

COMPLETE CODE: https://jsfiddle.net/yswdr7on/

Event A:

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

  if ($(this).val() == "S") {
     //
     //

  } else if ($(this).val() == "C") {

     $(".c").on(); //Não funciona.
     $(".recalcula").click(); //Esse funciona.

  } else {
     //
     //

  }
}).parent().find("input[name=situacao]:checked").change();

Event B:

$(".c").on('change', function(e) {

  if ($(this).prop('checked')) {

    //
    //
    //

  } else if (e.bubbles) {

    //
    //
    //
  }
  $(".recalcula").click();
}).change();
  • But $(".c").on( what? .c is a class?

  • Hello, yes, as the code is very large I thought it best not put to be cleaner the screen. I put in this link for better visualization https://jsfiddle.net/yswdr7on/

  • @Sam Can you help me?

  • @Sam doesn’t work either...

  • 1

    Tries $(".c").trigger("change")

  • @Sam worked, but not as I imagined. I’ll have to redo my code here....

Show 1 more comment

2 answers

0

Hi, we’re missing one if() in your code B.

Script:

    $(document).ready(function(){
        $("input[name=situacao]").on('change', function() {
            if ($(this).val() == "S") {
            } else if ($(this).val() == "C") {
                $(".c").on('change keydown paste input', function(e) {
                    if (true) {
                    } else if (e.bubbles) {
                    }
                    $(".recalcula").click();
                });
                $(".recalcula").click();
            } else {
            }
        }).parent().find("input[name=situacao]:checked").change();
    });

HTML:

<input type="checkbox" name="situacao" value="C">
<input type="text" class="c">
<input class="recalcula" type="button" value="Recalcula" onclick="console.log('RECALCULA...');">

If you want an event to occur every click put keydown by pressing the button, paste as a necklace, input by modifying.

  • I put the IF

  • As you suggested it didn’t work.

0


To call the event change in $(".c").on('change', function(e) {... you use the method .Trigger() jQuery:

$(".c").trigger("change");

Now, how .c is a class, will trigger the event the number of times equal to the amount of elements with the class .c.

  • Sam, see if you can help me with this problem https://answall.com/questions/373505/recalcular-ao-alterar-data-ou-clicar-no-radio-button

Browser other questions tagged

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