Hi there,

I would like to know how I could implement JavaScript into a PHP file.

For example, I have a web page that informs the browser to select the javascript.php to be the JavaScript file.
From there, the code of that file is
PHP Code:

echo "function validate_form() {

var username = document.getElementById(\"username\");
var password = document.getElementById(\"password\");
var status = document.getElementById(\"status\");

if (username.value.length <= 3) {

status.innerHTML = \"Username is too short!\";


return false;

else if (password.value.length <= 3) {

status.innerHTML = \"Password is too short!\";


return false;

else {

return true;



How can I use things like str_replace("", "", variable); and whatnot in JavaScript?
Because, I tried using it with a JS variable, but it didn't work... Any ideas?