Is there a way to set a cookie using JS and force a dynamic element reliant on the cookie to update without reloading the page?

apologies if the title question is confusing, but I’m not entirely sure how to ask or phrase this. Basically, I want a button to trigger (it opens a popup) on page load—easy enough.

However, the button is a “Find a Location” thing, so upon a user’s first-time (or cookie-less) visit, they see that button. If the user clicks it and inputs their location info, they get redirected to a page, and the button changes to one displaying their location, and the popup content also changes; the button gets fed a stored cookie with the location info, which is how the content updates.

I need to figure out a way to get this location info, via this cookie, injected on page load without the user having to enter their information at all, OR refreshing/navigating away from the page.

Right now, I have a function written to set the cookie upon load, and then automatically trigger the popup, but the button does not automatically update via the manual cookie setting unless the user reloads the page. I need everything to happen in one seamless motion. Is this feasible, or no?

I need to do this via Javascript, if it is even possible—no other methods, please. Also, this is not something I can do via the site’s back end or some CMS either.

Thanks.