I am trying to populate the calendar form field by using jQuery based on the values of other field. I am using JHTML::calendar
for this. When the value is set via php
everything works fine for me. But when I try to set it via jQuery
, it shows the value but when hit submit, the field becomes blank. Although, when I use tab (or focus) then date value saves properly.
Following is my code -
Via PHP
<?php if($session->get('ssdate')): $dateValue = $session->get('ssdate'); endif; ?>
<?php echo JHTML::calendar($dateValue, 'sdate', 'sdate', '%d-%m-%Y'); ?>
Via jQuery
//data.match_date is in format 01-10-2017
jQuery('#rq_form input[name=sdate]').val(data.match_date);
I referred to this post and tried chaning the format to yyyy-mm-dd and set the value but again it goes blank.
Reference: https://github.com/jquery/jquery-mobile/issues/2755
Change date format and set value
var d = new Date(jQuery('#rq_form input[name=sdate]').val()),
var dateValue = d.split("-").reverse().join("-");
//dateValue format = 2017-10-01
jQuery('#rq_form input[name=sdate]').val(dateValue);
$('#rq_form input[name=sdate]')
) is correct? Try console logging this to see if it actually exists