dave
dave

Reputation: 123

jquery datepicker, trying to show selected date

still new to jquery, so please bear with me.

Once a date is clicked on jquery datepicker, how can I display that date next to the calendar box?

This is what I have so far:

                $(function(){
                       $("#datepicker").datepicker({ minDate: +0 });

        });

As far as html, I have:

<div id="datepicker"></div>

Out of the things I've tried, it works if the date is displayed inside a "input" How can i display the date as pure text?

Upvotes: 0

Views: 13285

Answers (3)

thecodeparadox
thecodeparadox

Reputation: 87073

$('#datepicker').datepicker({
    onSelect: function(a, b) {
        $('#datepicker').val(Date.parse(a).add(1).day().toString('d/M/yyyy')); 
    }
});

you can change your dateformat

Upvotes: 1

Lauw
Lauw

Reputation: 1715

you can add a

<div id="alternate"></div>

next to the datepicker and then add the following:

in the datepicker you can add the onSelect event

$('.selector').datepicker({
   onSelect: function(dateText, inst) 
   {
      $('#alternate').text(dateText);
   }
});

or you can use

altField: "#alternate", altFormat: "DD, d MM, yy"

as explained on this page: http://jqueryui.com/demos/datepicker/#alt-field

Upvotes: 2

Riz
Riz

Reputation: 10246

This should work automatically means when you select a date that should appear in the textfield, ie. in your case, textfield with id ' datepicker'. Not sure if you have such textfield.

jQuery datepicker demo

another jquery datepicker demo

Upvotes: 0

Related Questions