Here you could read an article with some useful words: How to hide a JS Code
Also, you could use an obfuscation
You just need to realise that you can't hide a JS code from user, because browser should download it and execute. If you want to encrypt it you should send a pass to browser which user'll get too.
Just imagine: I'm telling you 1 and you should tell me the same. What would you tell me if I'd told you 2 ?
And ... here it is ... problem of all programmers. All programmers want hide their own code : ). Just ... believe me. It is.
One more suggestion is just to try this: Online Obfuscator
If you want to do this with a PHP code, try this:
// action.php
<?php
if ( !isset($_POST['show']) ) {
die('HACKER !');
} else {
echo '
<html>
<head>
<title>Main Page</title>
<body>
<div id="demo">DEMO</div>
<br>
<form action="action.php">
<input name="show" style="display: none;">
<input type="submit" value="Try me !"/>
</form>
</body>
</html>';
}
?>
These files should be in same folder.
// index.html
<html>
<head>
<title>Main Page</title>
</head>
<body>
<form action="action.php">
<input name="show" style="display: none;">
<input type="submit" value="Try me !"/>
</form>
</body>
</html>
Good luck : )