onchange not working for select created using dd

2.5k views Asked by At

I have created an select box using dd:

<select id="Size1"  class="mydds" style="width:180px;">
<option value="/p/1">1</option> 
<option value="/p/2">2</option>
<option value="/p/3">3</option>
</select>

Inside (document).ready I added the following line:

$(".mydds").msDropDown();

I tried to bind onchange using

$('.mydds').on('change',function() {
    alert("hiiiii");
});

But not able to bind the event can you help me on this?

4

There are 4 answers

0
Yester668 On BEST ANSWER
$(document).ready(function(e) {

  var myddsAux = $(".mydds").msDropdown().data("dd");

  myddsAux.on('change', myddsFunction);

  var myddsFunction = function ( event ){
      alert("hiiiii");
  }
});

;)

PD: Documentation msDropdown

0
MD SHAHIDUL ISLAM On

Following is working for me

$(document).ready(function(e) {

    $(".mydds").on('change', 'select', function() {
        alert($(this).val());
    });

});
0
Aleksandar Pavić On

You can get multiple variables from msDropdown, depending what you need,

here is example to get the text

        $(".mydds").change(function() {
            var oDropdown = $(".mydds").msDropdown().data("dd");
            var text = oDropdown.get("selectedText");
            console.log(text);
        });

there are also other properties available like:

  • selectedIndex - number
  • selectedOptions - array
  • value (select option value)
0
Digvijaysinh Zala On

Try this code

$(".mydds").on('change', 'select', function() {
alert(this.value);
});