I have a web app that when an employee comes in at work and scans his ID containing a barcode it shows their name on the screen and performs an insert to the DB for their attendance and the same way happens when they exit the office.
I later added a function that plays an audio file greeting them good morning and goodbye. Which works just fine. Now I wanted to upgrade this not just by playing a generic message but instead it says good morning plus their first name and goodbye plus their first name too.
I tried passing the ID no. of the employee to the JS playAudio('$id') which then selects the case of the switch statement case "id": idnoaudio.play(); but does not work.
If the insert query was successful it shows their basic details and plays a file. This works ok.
if($iResult){
$status="IN";
echo '<script type="text/javascript">', 'playAudio();', '</script>';
echo"<tbody>";
echo "<tr>";
echo "<td>".$getFname."</td>";
echo "<td>".$getLname."</td>";
echo "<td>".$getIdNo."</td>";
echo "<td>".$status."</td>";
echo "</tr>";
Then it calls a script inside the html body that looks like this, which also works fine.
<?php
include('audiofiles.php');
?>
<script type="text/javascript">
var x = document.getElementById("myAudio");
function playAudio() {
x.play();
}
</script>
The contents of audiofiles.php looks like this.
<audio id="myAudio">
<source src="./audio/villalobos.wav" type="audio/wav">
</audio>
I need a simple approach on how to do it. I was thinking of passing a php global variable to the same url upon submission and then assign that variable to JS. But can't come up with a simple code that would work. Please advise, any help is appreciated. Thanks.