Alex Rivera | Logout

How can I make a program wait for a button press in javascript?

Asked 2010-02-08T13:27:04.510
10

I need to modify some legacy javascript code. There's a place where I want to wait until the user presses one of two buttons and then continue with the program flow (like prompt() function). How can this be achieved ?

Edit
Report

2 Answers

4

You need to break your function at that point, and add another function to catch the user's button press event.

You can use Narrative Javascript to introduce blocking behavior and simplify it (so you don't need to break up your function into two part), but note that this library has been abandoned since 2013.

answered 2010-02-08T13:36:06.657
0

I wouldn't play with timeouts and intervals for that.

You'd be better off cutting the program in 2 parts, may be as you suggest in 2 functions.
Run the first part, add the code to ask the user for action.

And then based on the action, run the second part.

answered 2010-02-08T19:47:58.663

Your Answer