I'm not 100% sure on that but I think you can call a C2 function in javascript, just make it return the value of the variable you need and you should be ok, never tried though.
c2_callFunction("name", ["param1", "param2"])
source https://www.scirra.com/manual/149/function
EDIT: just tried it: https://1drv.ms/u/s!AjkoCSebIn9JiXcTHqtxEm0psfjb , it shows the variable name in the prompt and sets the result of the prompt to the variable
you may have to url encode it in the function to ensure no syntax error can be done.
EDIT 2: doesn't seem to be an issue with characters in the end, so url encoding it is not needed it seems.
in any case, you have to handle the fact the player may simply cancel the prompt too.
also rojohound solution seems to be easier and faster, did not read all the way through, duh, I'm dumb.