I am trying to call a javascript function from php. The function takes one argument. This is the call:
<?php
function welcomeBackMessage($user, $password){
echo "<h1>BACK: " . $user . "pwd " . $password . "</h1>";
echo "<script> welcomeBack({$user})</script>";
}
?>
This is the JS function; declared before the php functions calls it:
<script>
//Called form php to welcome back a guest
function welcomeBack(user){
print("JS WELCOME BACK CALLED");
var login = document.getElementById(loginbutton);
login.parentNode.removeChild(login);
}
The JS function never executes, and debuting the console I get the following:
<h1>BACK: guest2pwd 1234</h1><script> welcomeBack(guest2)</script>
Can't find variable: guest1.
The idea is to pass the variable to a JS function so I get update a DOM element with variable.
Any input appreciated.