Search code examples
javascriptjqueryhtmljquery-uidatepicker

jQuery datepicker field value not showing


I have a field on which I have implemented jQuery Datepicker but if I assign a value on that field its shows in the chrome's developer tool...

enter image description here

But its not showing on the front end.

I know we can set a default date like this with the datepicker option setDate:

$( ".datepicker" ).datepicker("setDate", '29-10-2016');

But the date is coming from database and I cannot hard code it... So is there any way I can add a value and it will show up on front end unless user changes and set another date?

<input type="text" name="date" id="date" class="datepicker" value="25-10-2016">


Solution

  • I found a way but still doesn't feel its the correct way, but for now this will do the trick for me.

    I'm posting this answer to help other and will wait and see anyone else come up with the best and efficient solution for this question.

    Since I'm using PHP so I just put this on my page to set the date for that field. I can add more lines if I have more date fields in my page...

    <script>
        $(function(){
            $('#date').datepicker('setDate', '<?php echo $date; ?>');
        });
    </script>