Syntax error: Illegal return statement in JavaScript
I am getting a really weird JavaScript error when I run this code: <script type = 'text/javascript'> var ask = confirm('".$message."'); if (ask == false) { return false; } else { return true; } </script> In the JavaScript console it says: Syntax Error: Illegal return statement It occurs at return true; and return false; (I am echoing this javascript from a php function; the $message variable is one of the php parameters) What is wrong with my code? return only makes sense inside a function. There is no function in your code. Also, your code is worthy if the Department of Redundancy Department.