Javascript onchange does not work for Combox

Asked

Viewed 29 times

0

I have a Function in javascript that works perfectly for a textbox

$('#Year').on('change', function () {
    alert("test"); 
});

However, for a combobox, it does not work

$('#EntityId').on('change', function () {
    alert("test"); 
});

I tried to use .change(function (){}) but it also doesn’t work

  • The error must be in HTML. O id must be different, duplicated or malformed.

1 answer

2

Use the Binder .change jQuery that works perfectly, although they do the same thing as your code according to the documentation:

As the . change() method is just a shorthand for . on( "change", Handler ), detaching is possible using . off( "change" ).

That is, an "abbreviated form" for the on("change")

Read more here: https://api.jquery.com/change/

$('#EntityId').change(function () {
    alert("test"); 
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="EntityId">
  <option>-- selecione --</option>
  <option>2020</option>
  <option>2019</option>
  <option>2018</option>
</select>

Browser other questions tagged

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