HTML and the web are stateless, which means that any web page that you are viewing is complete and there is no program running in the background.
To have a variable accessable across pages you either have to pass that variable using either an HTML form, or a URL with GET variables, or cookies. Or you can use Sessions which store variables on the server and give other pages access to them.