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

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

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 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