sree
sree

Reputation: 902

onchange not working for select created using dd

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?

Upvotes: 0

Views: 2537

Answers (4)

Yester668
Yester668

Reputation: 34

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

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

  myddsAux.on('change', myddsFunction);

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

;)

PD: Documentation msDropdown

Upvotes: 1

MD SHAHIDUL ISLAM
MD SHAHIDUL ISLAM

Reputation: 14523

Following is working for me

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

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

});

Upvotes: 0

Aleksandar Pavić
Aleksandar Pavić

Reputation: 3420

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)

Upvotes: 0

Digvijaysinh Zala
Digvijaysinh Zala

Reputation: 174

Try this code

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

Upvotes: 0

Related Questions