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

78
Visualizações
How to echo js variable with php form with onchange function?

So I'm building a booking system where with php I disabled all the unavailable dates now I need to get a selected date and display available times based on the selected date, meaning if there are more than 5 reservations for 1 time period in a selected date, input for that time period will be unavailable.

I'd do it with something like this

$sql = "SELECT time FROM reservations WHERE date=$date;  //date would be a js variable
//Then I would start the query and count the rows
if($count>5)
{ //here I would just make the input of that time period hidden}

But here is where my problem lies, I need to get the date variable before submitting the form I tried to do that with onchange function with js

<input type='text'class="form-control input-text js-input" id="date" name="date" onchange="getDate"/>

And whenever someone chooses the date I tried to get the date by this code, and try to echo it in php

<script>
   function getDate() {
       var selectedDate = document.getElementById("date").value;
   <?php $selectedDate = "<script>document.write(selectedDate)</script>";?>
   <?php echo "<p style='font-size:100px;color:white;'>$selectedDate</p>";?>
   }
</script>

I do not get the date displayed as I thought I should, I don't get any errors nor anything

about 4 years ago · Juan Pablo Isaza
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