Okay, here are something I have now.
I'd like to use $_SESSION['pass'] in my other php files to make it as a condition to check whether an if condition is true. But it seems that the system only shows the alert part and never runs the code in the PHP tag. 
Thanks a lot!
document.getElementById('pass').onclick = function(){
    <?php $_SESSION['pass']=1; ?>
    alert('here!');
}
document.getElementById('fail').onclick = function(){
    <?php $_SESSION['pass']=0; ?>
    alert('there!');
}


$_SESSION['pass']is set to 0, given that that's the later statement. Then the result of the script is sent to the client, which is the JS minus the PHP parts. If you want to run PHP code based on a button click, you need to run an AJAX request.