PHP can only be run before the page has sent (and is visible on a users browser). Javascript works only after the page has sent and is executed by the users browser.
If you want to change anything after the page has been sent and is visible, you need Javascript, but if it can be before you can use PHP.
To get a variable sent by a form (eg. method="post") you can have:
- echo $_POST['my_input_name'];
But that will only work once the form has been submitted to the server. Hope that makes sense.