Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

90
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda