1

My goal is to calculate and show end date based on my start date by date picker and doprdown to choose number of weeks.

I have Jquery datetimepicker http://xdsoft.net/jqplugins/datetimepicker/ to select start date and dropdown to select number of weeks.

I'm using below codes to get the end date result but its not working:

  week_number_id.on('change', function(e) {
var selectvalue = $(this).val();
//Display 'loading' status in the target select list
date_result_id.html('<i class="uk-icon-spinner uk-icon-spin"></i>');
if (selectvalue == '') 
{
    date_result_id.html(initial_date_result_html);
} 
else 
{
    //Make AJAX request, using the selected value as the GET
    $.ajax({
        url: 'index.php',
        data:'option=com_mycom&task=getmydateHTML&dvalue='+selectvalue,
        success: function(output) {
            date_result_id.html(output);
            updateSelect(date_result_id.val());
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert(xhr.status +  ' ' + thrownError);
        }
    });
}
});

and on php code:

  public function getmydateHTML() {
  $jinput = JFactory::getApplication()->input;
  $db = JFactory::getDbo();
  $query = $db->getQuery(true);         
  $dt = $jinput->get ('dvalue');
  $choosendate = $jinput->get ('start_date');       
  $newdate = strtotime("+". $dt . "week", $choosendate);
  echo   date('M d, Y', $newdate);     
 exit; // this will stop Joomla processing, and not output template modules   etc.
   }

But after calculation result shows date starting from jan 01, 1970, weeks are increasing correctly but the code can not get the start date.

  • Please progress this page to a system-recognized resolution. If one of the answers solved your issue, please award the best answer with the green tick. If both answers were helful, please upvote them both. If you need more support, please leave a comment under the answers and edit your question to clarify where you are stuck. – mickmackusa Jan 28 at 7:57
1

Your script doesn't send 'start_date' parameter anywhere, so it defaults to 01.01.1970. Add 'start_date' parameter to $.ajax data, or add default value to $jinput->get('start_date', some_default_val).

BTW. - exit; is not a good practice, there are better methods: https://stackoverflow.com/a/13479338/2877359

0

As the previous answer stated, the start_date parameter is not sent through the data field.

In any case, I don't know why are querying the server for this simple task - you can do this at the client's end. See this SO answer about this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.