I am trying to re-loop the display of user-inputted string. I am doing this using either setInterval or setTimeout (not sure which one)
So if a user submits 2 entries into a text-box form, those 2 entries will be displayed, one after another, repeatedly.
What follows is my code, taken from: jsfiddle.net/sean1rose/sKadX/4/
frm.submit(function(event) {
event.preventDefault();
container.push(txtBox.val());
var i = 0;
function myLoop(){
setInterval(function () {
output.text(container[i]);
i++;
if (i < container.length) {
myLoop();
}
}, 3000)
}
myLoop();
txtBox.val('');
});
As my code is now, if you input 2 different strings into the form, one after another, it will display one after the other (w/ a delay), but then it will stop at the last one (it won't re-loop).
How would I fix the code to get it to continuously re-loop the input so that it doesn't stop at the last inputted string, but instead restart at and display the 1st inputted string? (This should hopefully also work for more than 2 inputs. For example, if a user inputs 5 different entries, then it will loop thru and display those 5 over and over again)...