tags:

views:

104

answers:

1

I have some very simple jQuery hide/show logic called on a change in select list value in a Drupal form.

$(document).ready(function(){
  $("#field_id").change(function() {
    my_hide_show_function();
  });
});

I'd like to call this same function when the form is set up, to respond to the default (or previously submitted) value, but can't seem to do it. Specifically, I'd like to call it when a collapsed fieldset is expanded. How can I do this?

+1  A: 

Try this:

$(function(){
  $("#field_id").change(function() { //Trigger on change
    my_hide_show_function();
  }).trigger('change'); //Trigger once on load

  $("#myFieldset").resize(function() { //Trigger on resize
    my_hide_show_function();
  });
});
Nick Craver
Thanks, looks like a belt and braces solution but my function's still only getting called on the original change. I'm guessing the collapsed fieldset overrides the trigger on pageload, which leaves wondering whether .resize() recognizes the un-collapsing of the fieldset.
lazysoundsystem
Yes, I just tried the trigger with the fieldset uncollapsed and it works fine. Still curious about integration with collapsing the fieldset, though...
lazysoundsystem