R
R
Robot2015-11-17 12:01:48
JavaScript
Robot, 2015-11-17 12:01:48

How to get the result of a JS function?

Calendar date picker function works

// Выбор даты
calendar.selectDate = function(day,month,year) {
  calendar.selectedDate={
    'Day' : day,
    'Month' : month,
    'Year' : year
  };
  calendar.drawCalendar(month,year);
}

Out of function code
document.getElementById('test_id').innerHTML='Hello World!';

works, but inside the function does not work. But even outside the function, an attempt to display its result on the screen ends in failure - it displays either code, or says that the object, or nothing at all. How to output correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Robot, 2015-11-17
@iam_not_a_robot

Everything is simple, the second line from the bottom, just day+'-'+month+'-'+year

calendar.selectDate = function(day, month, year) {
    calendar.selectedDate = {
        'Day': day,
        'Month': month,
        'Year': year
    };
    calendar.drawCalendar(month, year);
    document.getElementById('test_type').innerHTML = day+'-'+month+'-'+year;
}

A
Andrey Dyrkov, 2015-11-17
@VIKINGVyksa

calendar.selectDate = function(day,month,year) {
  calendar.selectedDate={
    'Day' : day,
    'Month' : month,
    'Year' : year
  };
  calendar.drawCalendar(month,year);
 return this.selectedDate;//что вам мешает так сделать?
}
//можно получиться дату так
var date = calendar.selectDate(1,2,2015);

Is this a custom calendar?
You can pass the last callback argument to the .selecDate function, that is, what needs to be done at the end of the execution.
calendar.selectDate = function(day,month,year,callback) {
  calendar.selectedDate={
    'Day' : day,
    'Month' : month,
    'Year' : year
  };
  calendar.drawCalendar(month,year);
  callback();
}

//вот как использовать
calendar.selectDate(1,2,2015,function(){document.getElementById('test_id').innerHTML='Hello World!';});

Did I understand you correctly?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question