Please Assist.
I need to wait for an operation to finish before executing it again in javascript. These operations may be run at different times. Not all at once. I have a problem with running 2 operations at once since they execute at the same time.
Output should append text in a "textarea" using settimeout. It needs to wait for that to finish then starts typing the next text at whatever random index of the "arrayofrandomtext " array is called. Later on the "ProcessText(someint)" may still be called based on a keystroke etc.
- The existing text must be appended, not replaced at 0 instead appending i.e Hello World. Something else....
var index=0;
var arrayofrandomtext = ["Hello World","something else", "other stuff"];
function ProcessText(someint){
//These may run together
next_letter(arrayofrandomtext[someint]);
//wait to complete and rerun it with other text
next_letter(arrayofrandomtext[someint]);
//later on if the user hits a key this may run only
next_letter(arrayofrandomtext[someint]);
}
function next_letter(text){
if (index <= text.length) {
someControl.value = text.substr(0, index++);
setTimeout(function () { next_letter(text); }, 50);
}
}
someControl.value.