Christofer Ohlsson
Christofer Ohlsson

Reputation: 3145

Getting date from Jquery Datepicker

I have a little javascript function using datepicker in the following way:

function sanchobonanzaandtheballisticballcrunch()
{
    $( "#datepicker" ).datepicker();
    var currentDate = $( "#datepicker" ).datepicker( "getDate" );
}

that gets called from my .php file with this HTML button:

<button onclick="sanchobonanzaandtheballisticballcrunch();">Click here for DATE</button>

But as my understanding of Javascript is rudimentary, I can't figure out how to retrieve this date information (probably after reformating it from date object to String) to the calling file and store it in a variable. I am also not sure whether the value of currentDate updates whenever a new date is selected as is, or whether that only happens when the HTML button is pressed.

Upvotes: 0

Views: 3445

Answers (2)

felipekm
felipekm

Reputation: 2910

Try this:

function sanchobonanzaandtheballisticballcrunch()
{
    $( "#datepicker" ).datepicker();
    var currentDate = $( "#datepicker" ).val();
}

Cheers!

Upvotes: 1

Karthik Chintala
Karthik Chintala

Reputation: 5545

Try this

var currentDate = document.getElementById('datepicker').value;

Edit:

so, write an onclick event for that div

check fiddle here

Upvotes: 0

Related Questions