How can I set a variable set to something when a html link is activated?

For example I have an anchor tag to go to another page. Is there a way to activate a function which changes a variable?

With this variable, I want to open up a new page like: @app.route(/VARIABLE_HERE)

How would I go about setting a variable on a link click then opening the page? Thanks.

UPDATE 1:

I basically have a global variable named 'topic' which is set to 'maths'. I have an image which when clicked changes the value of 'topic' to 'english'.

UPDATE 2:

I didn't think of multiple users, I'm not advanced in this, I'm still learning. Basically my website is a revision tool. I have a list of subjects with topics. When the user clicks on a topic, a question will appear and the user will answer it. What I'm struggling with is that when the user clicks on the topic, I want them to be directed to the same page for every topic but I'm not sure how I can get that page to identify what topic the user has clicked. I thought by setting a global variable when the topic is clicked then reading that variable inside the questions page would work somehow but like you said, it wouldn't work for multiple users. How would I go about this?