Topic: How to trigger on change event under materialSelect() function

Alfonso Marrero pro asked 6 years ago


Dear All, I have a basic select:
<select class="mdb-select md-form colorful-select dropdown-primary">
<option data-ports="24" value="switch-24">Switch 24P</option>
<option data-ports="32" value="switch-32">Switch 24P</option>
<option data-ports="40" value="switch-40">Switch 24P</option>
<select
Trying to trigger the on change event to gather the data value and update few fields. I am using Jquery as follow:
$('.mdb-select').on("change", function(){ 
alert($(this).data('ports'));
});
So, I am not been able to triger the on change event, any suggestions? Thanks

Jakub Strebeyko staff answered 6 years ago


Hi there, I think that there is no problem with triggering an event itself, as much as with what is done in callback. Please check out this working example for reference. Hope it helps! Let us know whether it solved the issue. Best, Kuba

Alfonso Marrero pro commented 6 years ago

Thanks, here is the right way:

$('.mdb-select').materialSelect();
$('.mdb-select').on("change", function(event) {
    alert($(event.target).find(':selected').data("ports"));
});

Rgds,

A. Marrero



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.5.10
  • Device: PC
  • Browser: IE
  • OS: Windows
  • Provided sample code: No
  • Provided link: No