The basic approach is described here:
Feel free to ask if you require more detailed instructions.
There’s also an implementation of exactly what you describe in this template. It is intertwined with other code on the card, though, so the feature might not be as easy as copy and paste onto your cards, but should still be useful as a reference.