Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
Pass variable value from datepicker

I have a datepicker in which I create a variable and determine which day of the week we select

let dayofweek1 = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
let dayOfWeek = dayofweek1[e.date.getDay()];
console.log(dayOfWeek)

Full function:

$('#reservation-date').datepicker({startDate: '+0d'}).on('changeDate', function (e) {
            const arDate = e.date.toString().split(' ');
            let input = $('[name="RestaurantReservationForm[date]"]');
            let dayofweek1 = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
            let dayOfWeek = dayofweek1[e.date.getDay()];
            console.log(dayOfWeek)
            input.val(arDate[3] + '-' + (e.date.getMonth() + 1) + '-' + arDate[2]);
            _self.unSetError(input);
            $('#reservation-date .js-value').text(arDate[2] + ' ' + arDate[1]);
        });

And I want to use this dayOfWeek variable in another function

filterTimes: function () {
    if ((["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"].indexOf(dayOfWeek) >= 0)) {
      let workHours = getWorkHoursForDay(json, restaurantID, dayOfWeek);
      let items = document.querySelectorAll(".dropdown-menu.dropdown-menu-height-fixed li a");
      for (let item of items) {
        let itemValue = parseFloat(item.getAttribute('data-value'));
        item.parentNode.classList[((itemValue < parseFloat(workHours.open)) || (itemValue > parseFloat(workHours.close)) ? "add" : "remove")]("invisible");
      }
    }
  }

How can I declare this variable with the value of the selected day globally?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  1. Try declaring the variable outside the function.
  2. I've read that the variables that are not declared are scoped globally, but this is not a best practice.
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!