Need help populating dynamically created input element values using datepicker and .live event handler.

Need help populating dynamically created input element values using datepicker and .live event handler.

I have a table with a date field in each row:
  1. <input class='"datepicker" id="dp_XXXXX" value=""/>
The table, and the input id element,  are dynamically created from database records and I use jQuery live to initialize the datepicker for each field, like so:

  1. $('.datepicker').live('click', function() {
            $(".datepicker" ).datepicker();
            });

The idea is that when I click in the input field, the datepicker pops up and allows the user to input a date. While the date shows in the input field in the table, the value attribute of the input field is empty.  I can't use the getDate() method on the datepicker, since I can't programmatically connect the datepicker element in any particular row with the input element in that row. I tried the onClose method shown below, but that doesn't work either. Has anyone done this successfully?
  1. $('.datepicker').live('click', function() {
            $(".datepicker" ).datepicker({
                   onClose: function(dateText, inst) {
                       var pos = inst.id.indexOf("\\");
                       var id = "dp_" + inst.id.substring(0, pos);
                       $("input#dp_" + id).val(dateText);
                   }
                });
            });