Search code examples
javascripthtmlcssjavaquery

Date picker issue on form submit


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());

Solution

  • 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(); 
        }
    });