Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting value from JQUERY datepicker

If I want to display the JQUERY UI datepicker inline by attaching it to a DIV like $("div#someID").datepicker() - how do I access the chosen date? I assume if it's not bound to an INPUT then it won't be submitted with the form.

I guess as a followup, if I need to bind it to an INPUT element, is there a way to control the positioning of the datepicker relative to the INPUT element? If I wanted the datepicker to appear above or to the side of the element rather than below it, how would I do that?

Forgive me if this answer is somewhere really obvious.

like image 376
David Grenier Avatar asked Nov 16 '11 05:11

David Grenier


People also ask

How do I get the Datepicker value?

If you want to get the date when the user selects it, you can do this: $("#datepicker"). datepicker({ onSelect: function() { var dateObject = $(this). datepicker('getDate'); } });

How to get selected date from datepicker in jQuery?

$(document). ready(function () { $("#datepicker"). datepicker({ onSelect: function (dateText, inst) { var date = $(this). val(); alert(date); } }); });


2 Answers

If you want to get the date when the user selects it, you can do this:

$("#datepicker").datepicker({     onSelect: function() {          var dateObject = $(this).datepicker('getDate');      } }); 

I am not sure about the second part of your question. But, have you tried using style sheets and relative positioning?

like image 197
chapa Avatar answered Sep 25 '22 12:09

chapa


You can use the getDate method:

var d = $('div#someID').datepicker('getDate'); 

That will give you a Date object in d.

There aren't any options for positioning the popup but you might be able to do something with CSS or the beforeShow event if necessary.

like image 37
mu is too short Avatar answered Sep 21 '22 12:09

mu is too short