Use the same function on different elements in JQuery
<p>I have a group of selects (birth_year, birth_month and birth_day). I wrote this code which fills a drop-down with correct number of days of a month, disables the month, day drop-down if no year is selected etc. My problem is that I have another group of drop-downs (entry_year, entry_month, entry_day) on the form which i want to use this function with, and I have no idea how could I do that.</p>

<p>How can I modify this function to work with another set of select boxes?</p>

<pre><code>$(document).ready(function() {
  $('.sl_birth_year').change(function() {
    var birth_year = $('#sl_birth_year').val();
    if (birth_year != 0)
  $('#sl_birth_month').attr('disabled', false);
    else {
  $('#sl_birth_month').attr('disabled', true);
  $('#sl_birth_day').attr('disabled', true);
}
$('#sl_birth_month').val(0);
$('#sl_birth_day').val(0);
  }),
  $('#sl_birth_month').change(function() {
    var birth_year = $('#sl_birth_year').val();
    var birth_month = $('#sl_birth_month').val();
    if (birth_month != 0) {
  $('#sl_birth_day').attr('disabled', false);
  var post_url = "/index.php/admin/get_days/" + birth_year + "/" + birth_month;
  $.ajax ({
    type: "POST",
    url: post_url,
    success: function(num_of_days) {
      $('#sl_birth_day').empty();
      $('#sl_birth_day').append('&lt;option value="0"&gt; &lt;/option&gt;');
      for (var i = 0; i &lt; num_of_days; i++) {
        var string = '&lt;option value="' + (i + 1) + '"&gt;' + (i + 1) + "&lt;/option&gt;";
    $('#sl_birth_day').append('&lt;option value="' + (i + 1) + '"&gt;' + (i + 1) + "&lt;/option&gt;");
      }
    }
  });
}
    else {
  $('#sl_birth_day').val(0);
  $('#sl_birth_day').attr('disabled', true);
}
  });
});
</code></pre>
