Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

oninput does not fire on checkboxes?

The following code does not work on all input elements:

$(':input').on('input', function(){
  alert('boom shakalaka');
});

It has no effect on check-boxes even though they are input elements, and checking or unchecking changes its state.

I can add the change event too inside on() but then the same event will be fired twice on other input fields.

Is there any reliable input state-change event that is consistent for all form elements?

like image 496
thelolcat Avatar asked Jul 29 '14 17:07

thelolcat


2 Answers

There is no single event that would be authoritative, but you can bind to multiple events -

$(':input').on('change keyup input', function() {
    console.log('changed');
});

P.S. I wanted to give you a +1 for using 'boom shakalaka' in an example, but I digress.

like image 178
Jay Blanchard Avatar answered Oct 23 '22 16:10

Jay Blanchard


    <!--Why not just use onclick ?-->
    <!--Ur-->
    <script>
    $('input#checkbox').on('click', function(){
      alert('boom shakalaka');
    });
    </script>
    <input type="checkbox" id="checkbox">
    <!--Or-->
    <input type="checkbox" onclick="anyfunction();">
like image 2
Yakuza Avatar answered Oct 23 '22 14:10

Yakuza