if (условие){
// JS код
}
<?php
$a = true;
if ($a) {
echo "<script>alert(\"Hello\");</script>";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p id="someid"></p>
<?php
$a = true;
if ($a) {
echo "<script>document.getElementById(\"someid\").innerHTML = \"Пароль неверен!\";</script>";
}
?>
</body>
</html>