Click to See Complete Forum and Search --> : loop to open window, only opens last


lcscne
10-06-2003, 04:25 PM
function printReports()
{
var studentID
for (i=0; i<document.frmStudentList.elements.length; i++)
{
if(document.frmStudentList.elements[i].type == "checkbox")
{
if(document.frmStudentList.elements[i].checked)
{
studentID=document.frmStudentList.elements[i].name
("DurationRules.htm","ProgressReport","resize=off,titlebar=false,toolbar=no,width=560,height=185")
progrep=open("../Student/PvProgReport.asp?RosterID=303&StudentID="+studentID,"ProgressReport","resize=off,titlebar=false,toolbar=no,width=560,height=185")
}
}
}
}

My problem is that this code only opens the last window in the the loop. I hoped it would open a window per loop. Anyone spot my problem? Thanks

Dimitri
10-06-2003, 05:19 PM
Try this:

var progrep = open("../Student/PvProgReport.asp?RosterID=303&StudentID=" + studentID, "_blank", "resize=off,titlebar=false,toolbar=no,width=560,height=185");

If that doesn't work, try setting the window name as a variable that changes with each iteration. For example:

var foo = 0; // note: place this line OUTSIDE of the loop

var progrep = open("../Student/PvProgReport.asp?RosterID=303&StudentID=" + studentID, "test" + (foo++), "resize=off,titlebar=false,toolbar=no,width=560,height=185");

Dimitri

lcscne
10-08-2003, 02:17 PM
Thanks Dimitri,
Now one more, is there a way to set the x,y position of each window so that I can offset them down and to the right (cascade them)? Their all stacked on top of each other.

Dimitri
10-08-2003, 03:34 PM
use moveTo()

Here's a simple demo to give you an idea of how it works (and make sure you have popup killers disabled in your browser):

<html>
<body>
<script>
&nbsp;&nbsp;&nbsp;&nbsp;var totalWindows = 4;

&nbsp;&nbsp;&nbsp;&nbsp;for (var x = 0; x < totalWindows; x++) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var foo = window.open("","win" + x,"left=" + (x*210) + ",top=0,width=190,height=100");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foo.document.open();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foo.document.write("Sample Window #" + (x+1));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foo.document.close();
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;function cascade() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (var x = 0; x < totalWindows; x++) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var foo = window.open("","win" + x);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foo.moveTo(x*100,x*30);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foo.focus();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
</script>
<br><br><br><br>
<a href="javascript:cascade()">cascade these windows</a>
</body>
</html>

lcscne
10-08-2003, 03:48 PM
Thanks Dimitri, that works like a charm.