How do I trigger a button action programmatically?

Hey there. I have three buttons that copy data to the clipboard (all data, filtered data, and selected data). I would prefer to have a dropdown menu with a button that could replace the three buttons.

My first thought is to hide the buttons and then trigger the button actions programmatically. Is this possible in Retool?

My second thought is to write a javascript query that copies the desired data to the clipboard, but I’m having trouble figuring out how to do that (i.e. selecting the data to use with the execCommand(“copy”) method on document.

All thoughts and solutions are welcome. Thank you!

First off I would try out the clipboard API instead of execCommand(). Haven’t used it myself, but seems more straightforward than the old way.

Second, fire a js query from your drop down’s OnSelect event. In that query you can read which item was selected (dropdown1.value) and copy whatever is appropriate to the clipboard.