0

I have a fieldset that contains a bunch of input elements and which is initially collapsed when displayed to the user. I would like to attach an event handler on the a drop down list that is contained in the fieldset but I seem to be having trouble accomplishing this. I am using jQuery 1.5 and this is the code that I am using:

// Add a change listener to the specified select box.
$(document).delegate("select[name='type_config[format]']", 'change', function() {
    var selectedValue = $("select[name='type_config[format]']").find(":selected").val();
    console.log("the value you selected: " + selectedValue);
});

I thought using delegate would accomplish this as drop down is not initially visible. However when I change the selection in the drop down list nothing happens. I know the selector is correct as I tested it out in the console when the drop down is visible. Any ideas what I am doing wrong (or what I may be overlooking)?

j08691
  • 204,283
  • 31
  • 260
  • 272
user5013
  • 981
  • 4
  • 10
  • 21
  • I don't see any error at first sight but if the dropdown exist but is invisible, you should be able to use the traditional binding: `$("select[name='type_config[format]']").change(function(){...})` – Claudio Redi Aug 20 '13 at 20:56
  • 1
    Your code works in jsfiddle: http://jsfiddle.net/BkaHt/ – Kevin B Aug 20 '13 at 20:57

0 Answers0