0

I'm building a webpage that shows different countdown timers depending on the user's selection. How do I call the JavaScript function that has the countdown timer from inside the PHP code I need to know the user's selection?

The webpage shows Finnish upper-secondary school students the time left for their matriculation exam. There are 9 different test days every spring and fall depending on the subject.

I made a select menu with the id "subject" where the user can select the subject.

To make the timer I made empty p tags and gave it an id "chemistry-timer" that I then use in the JavaScript to call the function. (I used this tutorial from w3schools)

This is what I tried to get the "chemistry-timer" to show:

<?php 
    $subject1 = $_GET["subject"];
    if ($subject1 == "Chemistry") {
    echo "<p id="chemistry-timer"></p>";
?>

When I run it I get an error message saying "unexpected 'chemistry-timer', which is weird because when I call the function in HTML like so

<p id="chemistry-timer"></p>

it works fine.

JukkaK18
  • 25
  • 4

1 Answers1

2

It is a quote issue, should be:

<?php 
    $subject1 = $_GET["subject"];
    if ($subject1 == "Chemistry") {
     echo '<p id="chemistry-timer"></p>';
    }
?>
Pranay Bhardwaj
  • 1,059
  • 8
  • 9