Anna
Anna

Reputation: 203

Get date from datepicker

Hi this is my datepicker

HTML:

 <div class="field-birthday field-return" id="birthday-edit" style="display:none;">
   <div class="birthdaypicker"></div>
   <input class="hidden" name="birthday" type="hidden" id="birthday" >

And this is in the .js:

$('.birthdaypicker').datepicker({
    dateFormat: 'dd MM'
}).on("change", function(){
    var date = $('input[name="birthday"]').val($(this).val());
    console.log(date);
}).datepicker('setDate', "-30y");

I'm new in jQuery, js,.. and I'm quite lost, I need to get the value of the chosen date but I could not find any clear exemple about who to do it! Help is needed! Thanks!

Upvotes: 0

Views: 124

Answers (1)

Dhaval Marthak
Dhaval Marthak

Reputation: 17366

Change your code to this:

$('.birthdaypicker').datepicker({
    dateFormat: 'dd MM'
}).on("change", function(){
   $('input[name="birthday"]').val($(this).val()); // remove  var date and set date here
    console.log($('input[name="birthday"]').val()); // directly get date here
}).datepicker('setDate', "-30y");

Upvotes: 2

Related Questions