You must change the id to class and change $("#datepicker") to $(".datepicker") , as the identifiers must be unique / different.
Then wrap the jQuery code in $(document).ready(function(){ /*...*/ }); to make sure that the html elements are created in the DOM when javascript / jQuery code is executed.
The result will look like this:
<script> $(document).ready(function() { $( ".datepicker" ).datepicker({ showOn: "button", buttonImage: "calendar.gif", buttonImageOnly: true }); }); </script> <p>Date: <input type="text" class="datepicker" /></p> <p>Date: <input type="text" class="datepicker" /></p>
Here is a working fiddle: http://jsfiddle.net/GJHuf/1/
source share