0

How can I assign the currently selected date instead of new date() in the following code?

So from here each time when I refresh, it will give me currently selected date in textbox instead of becoming blank

$(".date-pick").datepicker('setDate', new Date());

1 Answers1

1

try this ..

use onclose event of datepicker to set the value of date .... "$(this).val()" this will have the value of currently selected date and set this value to Html Element using "document.getElementsByClassName('.date-pick').value"

$( ".date-pick" ).datepicker({
    onClose: function(dateText, inst) {
        document.getElementsByClassName('.date-pick').value= $(this).val(); 
    }
});
kavetiraviteja
  • 2,058
  • 1
  • 15
  • 35
  • I've edited your answer to improve readability, but you should include some semblance of an explanation –  Jul 08 '15 at 07:41