Link to home
Start Free TrialLog in
Avatar of softechnics
softechnics

asked on

setTimeout() sending a page twice

I have a web app running JSP pages under Struts/Websphere. I am trying to implement test code so I can do load/performance testing as follows:

1. Start a browser and log into the application
2. Press 'F2' on the page and it sets a flag putting the client in loop mode.
3. Press the form's submit button
4. The next lookup page checks the loop flag and, as a result of it being set, calls the sendLoopTestPage() function, which automatically submits the form with a new item (selected randomly from an item code array).

I have the following Javascript function:

function sendLoopTestPage() {
form.ITEMCODE.value = itemCodeArray[Math.floor(Math.random() * itemCodeArray.length)];
setTimeout ("form.submit()", 2000);
return;
}

Problem: This function causes the page to be submitted twice. If I replace the setTimeout() function call with a dummy function that does nothing, the page is not sent at all, unless I press the form's submit button.

Any ideas why the form is being submitted twice?


Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Check this:

function sendLoopTestPage() {
  document.forms[0].ITEMCODE.value = itemCodeArray[Math.floor(Math.random() * itemCodeArray.length)];
  setTimeout ("document.forms[0].submit()", 2000);
  return;
}

If that does not help, then show the part of the generated html page source in browser that does call that sendLoopTestPage() function.

Avatar of softechnics
softechnics

ASKER

Zvonko,

Thanks for your response. I found the problem. I had moved some code from the JSP to the server, but didn't remove it from the JSP, so the method was being called twice, hence the two transactions. I contacted Community Support to delete the question, but your response must have come in before they got to it.

Doug
ASKER CERTIFIED SOLUTION
Avatar of PashaMod
PashaMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial