Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

77
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!