开发者

jquery datepicker code not working (set specific date as default)

I am trying to set the date to a specific one on page load so I'm trying this code:

    <script type="text/javascript">


    $(document).ready(function() { 

  var queryDate = new Date();
queryDate.setFull开发者_C百科Year(2009,11,01);
$('#date').datepicker({defaultDate: queryDate});


$("input[type='submit']").click(function(e) {
            e.preventDefault();
            $.post("s.php", $("form").serializeArray(), function(message) {
                window.location="v.php" 
            });
        });
    });

</script>

//The form part where is displays the datepicker:

<form action="#" method="POST">
<div data-role="fieldcontain">
<label for="date">Date:</label>
<input type="date" name="date" id="date" value=""  />
<input type="submit" value="submit" />
 </div>     
</form>

The problem is that nothing's changing ... the default is still the current date :o/

Any ideas anyone please?

UPDATE: Tried this code:

var queryDate = new Date(2009,11,01);
$('#date').datepicker({defaultDate: queryDate});
$('#date').val(queryDate);

And the date is appearing in the input box but the calendar is not in the right month nor date ... Moving foward but still not working.


I'm not sure sure the suggested answer here is not working. As I have tested it display on the right month and year, but only not highlighted the date. This could be because the date format.

Try adding this code to have a default value on your date.

$('#date').val(queryDate);

Then you may see that the format is different with the date in date-picker. If you manage to set the right format with date-picker, you get the things you wanted.


Umm what if you tried this

new Date(year, month, day, hours, minutes, seconds, milliseconds)

var queryDate = new Date();
queryDate.setFullYear(2009,11,01);
$('#date').datepicker({defaultDate: queryDate});

Then the datepicker knows its a date object and how to handle it.


EDIT Ok - all i did was copy the code exactly as you got it here several posts the same suggestion- and the code you edited. Added tags- inlcuded jquery and jquery ui.. I see no problem- the defuatl date is 2009.

</head>
<script src="jquery.min.js" type="text/javascript"></script>
<script src="jquery-ui.min.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function() { 
var queryDate = new Date();
queryDate.setFullYear(2009,11,01);
$('#date').datepicker({defaultDate: queryDate});

$("input[type='submit']").click(function(e) {
        e.preventDefault();
        $.post("s.php", $("form").serializeArray(), function(message) {
            window.location="v.php" 
        });
      });
   });
  </script>

</head>

<body>
//The form part where is displays the datepicker:

<form action="#" method="POST">
<div data-role="fieldcontain">
<label for="date">Date:</label>
<input type="date" name="date" id="date" value=""  />
<input type="submit" value="submit" />

</div>     
</form>

</body>

Result (no styles sheet attached)

jquery datepicker code not working (set specific date as default)

Working example- tell me what is wrong

http://jsfiddle.net/ppumkin/nptgn/


Try this

  var queryDate = new Date(2009,11,01);<br/>
  $('#date').datepicker({defaultDate: queryDate});


I was having a similar problem, I solved it like this

$('.datepicker').datepicker({dateFormat: "yy-mm-dd", defaultDate: "+3m"} );


Try this

$('#mydate').val("2009-11-01");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜