Unable to print 2nd doc loaded into iFrame

I have been fiddling and fussing with this JS code for close on a week now, and have finally got it to where it is producing 95% of what I actually need. But I’m out of ideas for how to push it the 5% to full success.

The idea is to be able to produce as many FormB/Transaction Sheets as one FormA may need. Each sheet can have up to 50 individual transaction entries; each FormA should be able to have an XXX number of transaction sheets attached. So the end users want to hit ONE Print button, and have the entire package print out. It’s going to be hard enough to convince them they’re still going to have to click PRINT in the Print Dialog Box for the Main and subsequently for EVERY related Transaction Form, but this is the best compromise I could think of that didn’t involve expecting the end user to actually remember to print one, print ALL.

The 5% non-working part comes in when I have two Transaction Sheets/FormBs in addition to the main FormA. FormA prints out just fine. The first FormB loads into the iFrame, and prints Just Fine. The second FormB APPEARS to load into the iFrame on screen; but only a blank page prints. The loop ends without incident after that, the form submits, and WebQuerySave() cleans up and redirects as expected.

Is it that I can’t reuse iFrames? Or I have to reinitialize it before reloading? Or…what? I’m at a loss.

I have discovered (the long, tedious, hard way) that the order of the statements below is critical. It’s taken me this long to get the statements into an order that will do even 95% of the task; previously, the best I could manage was about 60%.

function printallthis()

{

// All values are being taken from the “Main” form open on the screen

var f = document.forms[0];

//f.Submitted.value = “1”;

webaction.value = “submitandclose”; // WebQuerySave is going to need this

var atrans = alltransid.value; // a text list of all related Transaction Sheet IDs. Minimum 1,

									// Maximim infinity and beyond

var arrtrans = atrans.split("; "); // put the IDs into a JS array

var dbsvr = dbserver.value; // for building the href

var dbname = dbf.value; // ditto

var tlen = arrtrans.length; // how many Transaction Sheets/IDs to print

hloc = window.location.href;

window.focus();

window.print(); // print the CURRENT document

// slow up the end user with fast clicker fingers

alert(“Waiting for the Main Dispute Document to print. Please wait for the Print Dialog message box to appear. Do NOT close this dialog box until you have clicked the Print button on the Print Dialog.”);

var cnt = 0;

for(x=0; x<tlen; x=x+1) // iterate through the Trans Document

{

for(xx = 1; xx < 2000; xx=xx+1) {};		// I can't get setTimeout() to work for nuthin'

var pvar = arrtrans[x];					// the first Transaction ID

cnt = cnt + 1;							// Transaction Sheet page number



nwin = "http://" + dbsvr + "/" + dbname + "/TransIDLookup/" + pvar + "?OpenDocument"; // Trans Sheet url



frames['printiframe'].location.href = nwin;	// load the Trans Sheet into the iFrame



window.frames['printiframe'].focus();

window.frames['printiframe'].print();

	for(xx = 1; xx < 2000; xx=xx+1) {};		// give it a bit

alert("Please the PRINT button on the Print Dialog Box  to print Transaction Sheet " + cnt +". Then click OK to close this message box");	

for(xx = 1; xx < 10000; xx=xx+1) {};		// give it another bit



} // repeat, rinse



for(xx = 1; xx < 10000; xx=xx+1) {}; // tap fingers



alert("This Dispute Form Has Been Printed and Submitted");

window.location.href = hloc; // reload the Main document (clears out the Iframe)

f.submit(); // defer to WebquerySave() and let it clean up afterward.

}