Quick Short answer
Create a html hidden field, can be accessed, both, by JavaScript, and PHP, at the same time.
Extended Boring answer
Developing a web page is different than developing a desktop application.
When a html page has controls, like text, radiobuttons, checkboxes. And the web page was generated dinamically using PHP. And the user sends them back to the server, the values can be accessed like variables in php.
There is something called "hidden field" that acts like a variable, or control, but, its contents, its not displayed, as it happens with a textbox control.
Remember that a webpage is executed 2 times, first, generated at the server, using PHP, HTML or another web language, and later, at the client's browser, with HTML, and JavaScript, if there is any.
Summary
You may want to learn about how html controls are generated and read back int PHP, and access with Javascript.