Well, here is what I wanna do:
I have a text field and a textarea that both act as a console window. I am developing a very basic simulation of an interpreter with its own programming language with javascript (jQuery), so when I start executing a program that the user has previously typed, I go through all the instructions and when an special instruction is reached (“leer”) The user has to type something into this console and pause the execution of the program, I know that the user is done typing when the ‘return’ key is pressed. When that happens the program continues its normal execution flow.
Now, this behavior is quite similar to the one of a confirmation box, because it waits for an input and when the user presses any button (yes/no) the execution continues.
I hope I have explained clear enough so that all of you guys know what my problem is. I know it would be great to place some code here, but I don’t really know what part of it would help, so in case you need some chunk of code just let me know.
Here is how the page looks like.

and here is the code used to execute every single program:
this.ejecutarPrograma = function(pidprograma) {
var programa = this.listaProgramas[pidprograma];
if(programa == undefined) throw "ERROR!, PID no encontrado"
var posIni, posEnd;
posIni = programa.obtenerRbp();
posEnd = programa.obtenerRlc();
this.cp = posIni;
var temp = this.memoria[this.cp].split(/\s+/);
while (this.cp < posEnd || temp[0] != "retorne") {
try {
if (temp[0] == "vaya") {
this.cp = ACCIONES[temp[0]](this.cp, temp[1], programa);
}
else if (temp[0] == "vayasi") {
this.cp = ACCIONES[temp[0]](this.memoria[0], this.cp, temp[1], temp[2], programa);
}
else if (temp[0] == "nueva" || temp[0] == "etiqueta" || temp[0] == "retorne") {
// nada de nada por aca porque estos ya estan implementados
this.cp++;
}
else {
this.memoria[0] = ACCIONES[temp[0]](this.memoria[0], temp[1], programa);
this.cp++;
}
var temp = this.memoria[this.cp].split(/\s+/);
}
catch (e) {
throw "Linea " + (this.cp).toString() + ": " + e;
}
}
};
ACCIONES is an associative array that keeps the names of the instruction and as a value has the function, the instruction “leer” is empty it just gets a value from the input and copies that value in a variable of the program
Thanks for everyone’s help.
I’m not sure I completely understand the question, but it sounds like you’re looking for the
promptfunction.For example:
After the user clicks OK, the input is returned as a string. If they click cancel, null is returned.
Edit:
After seeing your comments on imsky’s answer, I think I have a better understanding of what you want to do. Correct me if I’m wrong.
You have a loop that you want to run continuously until the user does something, at which point you want your loop to wait for the user to finish, then continue execution of the loop?
If this is the case, try putting your loop in a function and use
setTimeout(yourfunction,0); Every iteration of the function, check if the user has done something (which means setting a variable when the user does something and checking it from withinyourfunction(). If the user hasn’t done something, continue looping (by using the setTimeout trick), otherwise do whatever you need to, after which you can again callyourfuntion(). The only catch here is that you can’t interruptyourfunctionin the middle of exectution, just inbetween each “loop”.Here’s an example: http://jsfiddle.net/PYabX/
Does this make sense, or am I completely off?