views:

96

answers:

3

I want to display the datepicker when page loads

$("#dp").datepicker("show");

but it is not working.

A: 

Try this:

$(window).load(function(){
  $("#dp").datepicker("show");
});
Sarfraz
Can i do this with 2 datepickers?
Jasl
A: 

You need to previously have attached the datepicker:

$("#dp").datepicker();
$("#dp").datepicker("show");
kgiannakakis
A: 

Make sure you call the attach function only after the document has finished loading (otherwise you could be trying to attach to a dom element that doesn't yet exist).

$(document).ready(function(){
  $('#dp').datepicker('');
});

Also, make sure you have referenced the JQuery library correctly:

<script type="text/javascript" src="jquery.js"></script>

Or try using Microsoft's or Google's CDN-hosted versions:

<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”&gt;&lt;/script&gt; 

Or

<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
SimonF