Uncaught TypeError: Cannot read property 'split' of undefined - bootstrap datepicker
datepicker, jquery, twitter-bootstrap
Solution
Try to change your selector to this:
$('#finalModal .datepicker').datepicker({
format: "dd.mm.yyyy"
})
This fixed it for me.
Problem
i am using bootstrap datepicker for the input in bootstrap modal window. When I opened this windows for the first time, everything is ok and datepicker works fine. When I close this modal window and opened it again, my js console says `Uncaught TypeError: Cannot read property 'split' of undefined` I'm loading form in modal window with ajax. This is my modal window: ``` <div id="finalModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3 id="myModalLabel">Final date</h3> </div> <div class="modal-body" id="finalModalBody"> </div> <div class="modal-footer"> <button id="finalSubmit" class="btn btn-success">Save</button> </div> ``` After loading this window, this script is started: ``` $('.datepicker').datepicker({ format: "dd.mm.yyyy" }) ``` And this is my formin modal window: ``` <form> <p><select onfocus="this.onmousewheel=function(){return false}" class="prereservationSelect" name="prereservation" id="frmfinalForm-prereservation"><option value="89">15. 7. 2014 - 19. 7. 2014</option><option value="0">second date</option></select></p> <div id="otherDate" style="display: none"> <p><strong><label for="frmfinalForm-otherDate">Zvolte jiný termín:</label></strong></p> <p style="float: left"><input type="text" class="datepicker text" name="otherDate" id="frmfinalForm-otherDate" value=""></p> <p style="margin-top: 15px; margin-left: 250px" id="date"></p> </div> </form> ``` Thanks for any advice.