I am running a JavaScript file on page load, however since the page reloads after clicking the search button the variable is redefined and the loop starts from the beginning again. Here is my code.
var acctNum = ["8AXXXXX0",
"8XXXXXX1",
"8XXXXXX2"]
var i = 1;
function myLoop () {
setTimeout(function () {
console.log(i);
document.getElementsByName("customerAccountNumber")[0].value=acctNum[i - 1]; //enter account number
$("[name='listUsers.x']").click(); //search
i++;
if (i < acctNum.length) {
myLoop();
}
}, 3000)
}
myLoop();
The code works for the first iteration but like I said since the page reloads i is redefined and it simply just loops through the very first account number. Any help would be appreciated.
Thank you,