Either make the page fully reload when a variant is selected, rough examples available on the forums through search.
Or you need an advanced customization to integrate it with your themes javascript for when options are changed by users.
Note shopify has a tutorial for some vintage themes here: https://help.shopify.com/en/manual/online-store/themes/os/customize/show-remaining-quantity
Part the complication here is shopify don’t put inventory data the frontend rest axja api so third parties cannot bulk scrape that from merchants stores.
So this means reloading the page for that 1 specific variants inventory, or purposefully putting the inventory counts in javascript or the html to be referenced by your javascript.
To get the dynamic version of this customization contact me at paull.newton+shopifyforums@gmail.com with this topic url, store url ,and theme name.