Arun Arun - 10 months ago 67
jQuery Question

Set Date to the Jquery UI datepicker input textbox

I am using jquery ui datepicker.and its working fine .my need is to set the date to the textbox when querystring contain any date

eg my url is


so I want to set this date to input textbox.

my input box html is

<input type="text" id="datepicker" class="txt-cal hasDatepicker" name="addFromDate" date_name="2013-12-11">

I tried some thing but no result.

$(function () {

var myDate = ?/*how to select the date_name from input textbox
$('#datepicker').datepicker('setDate', myDate);
$('#datepicker2').datepicker('setDate', myDate);
$('#datepicke3').datepicker('setDate', myDate);
$('#datepicker4').datepicker('setDate', myDate);


Thanks in advance


A better approach will be using custom data attribute.


Now you can access it

var myDate = $("#datepicker").data("date");
$('#datepicker').datepicker('setDate', myDate);


I doubt you're trying to get it from url(ie, query string)

If so check this answer, where a method is written to get

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(;
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));


var myDate = getParameterByName("date");