0

Possible Duplicate:
datepicker not working into new tabs

When I click button "add tab". Jquery will create new tab and new datepicker for me. But I can't get date on new datepicker. It is null. How to selector new datepicker into new tabs ??

My code

<script>
var tabCounter = 2,
    tabTemplate = "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span></li>";
var tabs = $("#tabs").tabs();
var tabContentHtml = $("#tabs-1").html();

Create datepicker

datepicker();

Function create picker

function datepicker(){
  $( ".rush" ).datepicker({
      changeMonth: true,
      numberOfMonths: 1,
      minDate: myDate,
      onSelect: function( selectedDate ) {
        // day is null for new tabs
        var day = $( ".rush" ).datepicker('getDate').getDate();
      }
  });
}

Add new tabs when click button

$("#add_tab").click(function(){
        addTab();
});
function addTab() {
        var label = "Tab " + tabCounter,
            id = "tabs-" + tabCounter,
            li = $( tabTemplate.replace( /#\{href\}/g, "#" + id ).replace(/#\{label\}/g, label ) );

        tabs.find( ".ui-tabs-nav" ).append( li );
        tabs.append( "<div id='" + id + "'><p>" + tabContentHtml + "</p></div>" );
        tabs.tabs( "refresh" );
        // Create new datepicker into new tabs
        datepicker();
        tabCounter++;
    }
</script>

Code html

<div id="tabs">
<ul>
    <li><a href="#tabs-1">Nunc tincidunt</a> <span class="ui-icon ui-icon-close">Remove Tab</span></li>
</ul>
<div id="tabs-1">
    <input type="text" class="rush" />
</div>
</div>
<button id="add_tab">Add Tab</button>  
Community
  • 1
  • 1
user1761176
  • 103
  • 3
  • 4
  • 16

1 Answers1

0

Try replace $( ".rush" ).datepicker('getDate').getDate(); by $(this).datepicker('getDate').getDate(); to avoid selectiopn confusion in your function.

function datepicker(){
  $( ".rush" ).datepicker({
      changeMonth: true,
      numberOfMonths: 1,
      minDate: myDate,
      onSelect: function( selectedDate ) {
        // day is null for new tabs
        var day = $(this).datepicker('getDate').getDate();
      }
  });
}
sdespont
  • 13,915
  • 9
  • 56
  • 97