You are mixing the JavaScript with PHP ! Once the page is echoed or displayed on the user's browser, what you get is the output of the PHP code! If you wish to communicate with the PHP page and dynamically change the contents, you could use AJAX. jQuery library has 3 or 4 AJAX extensions. Have a look at it.