I have a requirement to open multiple windows with most of same but few different values (Chrome n IE is not executing below code as expected). Here is piece of javascript code in my way..
function test(){
for(var i=0; i<3; i++){
var eForm = document.forms[0];
eForm.action = "demo_form.asp?targetNum="+i;
eForm.target = "_blank";
eForm.submit();
}
}
And this is my html form..
<form method="post">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="button" value="Submit" onclick="test();">
</form>
This code is running perfectly with firefox and as expected opening 3 tabs. But with chrome & IE it opens only one window (not sure if it is overriding previous windows in same tab). In chrome it shows window with last targetNum as 2 and in IE it shows first targetNum i.e. 0.
My aim is to achieve the behavior of firefox with chrome and IE as well i.e. to open multiple windows with respective form values.
Somewhere while looking for the soln I found a forum post which says to add onsubmit="this.action=this.action + '1';" under my form tag, tried the same but it didn't worked.
P.S.: Cant use window.open as I am populating values from java bean and that get override with last window opened.
not sure you are looking this kind of solution. i have modified your script like below. Hope it will help you.
var i=0;
function test(){
var eForm = document.forms[0];
eForm.action = "demo_form.asp?targetNum="+i;
eForm.target = "_blank";
if(i!=3)
{
setTimeout(function(){ i++; eForm.submit(); test(); },100);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With