Javascript - can't get return value - alerts fire prematurley
Hi Using Ubuntu 20.04
Can't get a return value from functio getChoice(). Also how do you stop the alert functions from going off prior to data being fed to them?? I know this is related to the 'return' problem but I can't discover how to fix this. Thanks for help in fixing. R Code:
Code:
Excerpt from dropdownDB.js |
Quote:
|
I'll try again. Hopefully this explains my problem a litttle better.
I am trying to use a dropdown box but can't get selected value outside of $("#selbox").on('click', function (). I have tried using return but that doesn't work. Any help greatly appreciated. R Code:
Quote:
|
Hi
You are mixing up async functions vs callbacks and regular functions. If you think about it, the getChoice function cannot work. What it does is basically: - show some html (a header and a select box). - set up a callback function so when you click on #selbox, that function will be called. - return - all done When getChoice returns, you have not selected anything. If you want to do something when something in the select box is selected, do it in the callback function. Or another strategy is to make another button that does something. Then you can simply check $("#selbox option:selected").text() and give an error message if nothing is selected. |
Thank you Guttorm,
I followed your suggestion and it all worked out fine!!!! R |
All times are GMT -5. The time now is 01:28 PM. |