Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

94
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda