How do you set a JavaScript variable when a link is clicked (to open a specific part of a popup)

I’m trying to make a link that shows a glossary popup when you click it. It should run a script that changes the variable “WordId” to the html element id of the heading that corresponds to the definition of the word.

I tried this:

<a onclick="BrowserPopupGlossary()" onclick="WordId = "...";">...</a>

This is the BrowserPopupGlossary function:

var WordId;
function BrowserPopupGlossary() {
    window.open('glossary.html'+'#'+WordId,'popUpWindow','height=500,width=400')
}

Any advice on how to optimize / fix this?