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

185
Vistas
Resubmitting a date (HTML) without refreshing page once a submission is made

I am creating an HTML page that takes a date from an input type="date" and returns the zodiac sign for that date. I have used a JS function to split the date into an array and use the indexes to isolate the month and day. The program runs as expected and displays the correct zodiac sign. But, if I submit the date and then change it, it keeps the original selection, unless I refresh the page.

Is there a way to change the input without refreshing the page? Or once submitted, is it static?

I select a date that displays the zodiac sign e.g. 'Taurus', then without refreshing the page, I select a date that represents 'Aries', but the display remains 'Taurus'. Do I need to refresh the page if I want to select and resubmit a different date or is there a way to achieve this without refreshing the page?

let userDate = document.querySelector('.selectedDate').value;
document.querySelector('.enterDate').addEventListener('click', findZodiac);

function findZodiac() {
  let sign = "";
  let selectedDate = new Date(userDate);
  let month = (selectedDate.getUTCMonth()) + 1;
  let day = (selectedDate.getUTCDate());
  let zodiacDisplay = document.querySelector('.starDisplay');

  if (month == 3 && day > 20 || month == 4 && day < 20) {
    sign = "Aries";
  } else if (month == 5 && day < 21 || month == 4 && day > 19) {
    sign = "Taurus";
  }

  zodiacDisplay.innerText = sign;
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The problem is that you are pre-caching the initial value of the form:

let userDate = document.querySelector('.selectedDate').value;

Then every time findZodiac() is called it is still referring to the stale copy of userDate. There's no reason you can't query and manage that value locally inside the findZodiac function.

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