How to use a datepicker?

How to use a datepicker?

The datepicker I want on my page needs to be regionalized and when the user selects a date, the selected date should be displayed in an alert. Seems quiet simple.

I tried with the following code. The selected date is shown, but the regional settings are not applied to the datepicker:
  1. $("#myDatepicker").datepicker({ 
          onSelect: function(dateText, inst) {
                alert(dateText);
          }
    });
    $("#myDatepicker").datepicker($.datepicker.regional['nl']);






When I switch the statements, the behavior is switched too: the regional settings are applied correctly, but I don't get the alert.


When I make use of the extend function, I get the desired behavior.
  1. $("#myDatepicker").datepicker(
          $.extend({
                onSelect: function(dateText, inst) {
                      alert(dateText);
                }
          },
          $.datepicker.regional['nl']
    ));







I just wanted to know if this is the correct way for having both working, because it's not a simple/easy solution (had to use google to find it and jquery's main purpose is to make the developer's life a whole lot simpler). So I guess it can be done a bit simpler. If it can't and this is the way it should be done, why do you need to use the extend-function, because I tried without it and it didn't work at all.

note 1: I know of the setDefaults-method on the datepicker, but it is in an offside position for this question
note 2: in the zip-file 3 files are provided with the different behaviors I described above.