1

I have a datepicker as shown in this JSfiddle. I need to get the value of that datepicker and display it below calendar without any text box. How can I do it?
I tried

alert($("#datepicker").val()); 

and

alert($("#datepicker").getText());

and

alert($("#datepicker").getValue());

But it didn't work. How can I implement this?

Matthieu
  • 563
  • 1
  • 7
  • 25
qwertymaster
  • 341
  • 1
  • 6
  • 22

2 Answers2

5

You can use onSelect

$("#dp").datepicker({
  buttonImage: '//placehold.it/32',
  buttonImageOnly: true,
  changeMonth: true,
  changeYear: true,
  showOn: 'both',
  onSelect: function(value) {
    $('#mydiv').text(value)
  }
});
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/redmond/jquery-ui.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.js"></script>

<input type="hidden" id="dp" />
<div id="mydiv"></div>
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
2

You can also use $('#').datepicker('getDate');

This is very similar to an existing question if you want to see more answers: Getting value from JQUERY datepicker

Community
  • 1
  • 1
Jonathan Holland
  • 607
  • 9
  • 18