I do that a lot in various ways (Perl, JavaScript), building the options for a select and dropping that into the HTML prompt with JavaScript. You do have to understand how to create a Select.
Rather than describe the process here, I'll just point you to Macro Reporter Macro (for a complex JavaScript example) and A Few Favorites Macro (for a simpler Perl example).
If you run those macros, right click on the prompt to Inspect Element
and see the HTML the code creates.