ingh.am
ingh.am

Reputation: 26742

Get datepicker value using jQueryUI

Using the jQuery UI, how can I get the value of the date picker in the http post when it's used like this within a form:

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

Upvotes: 18

Views: 96680

Answers (6)

spedy
spedy

Reputation: 2360

This worked just fine for me:

$("#datepicker").find(".active").attr("data-date")

Upvotes: 0

user669677
user669677

Reputation:

Init:

$( "#datepicker" ).datepicker({ dateFormat: "yy-m-dd" });

Get value:

$("#datepicker").datepicker().val() //2014-4-15

See format settings at:

http://api.jqueryui.com/1.9/datepicker/#option-dateFormat

Upvotes: 6

jk.
jk.

Reputation: 14435

$('#datepicker').datepicker({
    onSelect: function(dateText, inst) {
      $("input[name='something']").val(dateText);
    }
});

Here's a fiddle: http://jsfiddle.net/jensbits/9hbmy/338/

Upvotes: 31

Thorsten
Thorsten

Reputation: 5644

Add a hidden field and add it to the "altField" option should do it.

Edit: You might also want to check out this solution:

HTML:

<div id="datepicker">KLICK ME</div>
<input type="hidden" id="hidde_date_field" />

JavaScript:

$('#hidde_date_field').datepicker();

$('#datepicker').click(function() {
    $('#hidde_date_field').datepicker( "show" );
});

Upvotes: 1

Clayton
Clayton

Reputation: 5350

You should tie the datepicker to a form input instead of a div, so the value in the input will be submitted back with the form.

<input type="text" id="datepicker"></div>

<script>
    $(function () {
        $('#datepicker').datepicker();
    });
</sript>

Upvotes: 2

codeandcloud
codeandcloud

Reputation: 55200

Are you looking for this.

$("#datepicker").datepicker("getDate");

Upvotes: 27

Related Questions