Comike14
September 22nd, 2005, 11:15 AM
I've got a lot of programming experience, but this bit of scripting is giving me some trouble. What I'm trying to do is display the contents of an array to a new window. I know that according to this snippet, it won't print pretty and nice, but I'm just trying to clear the syntax errors before I worry about formatting! I get an "unterminated string constant" error in the last "writeln" command of the second function. Please, if anyone has any insight, I'd really appreciate it:
function Parse(form){
alert("Parsing...");
var supervisors = new Array();
var nuBody = "";
supervisors = getSups();
alert(supervisors[0]);
var arrayLength = supervisors.length - 1;
var sups = arrayLength / 3;
alert("Array has " + arrayLength + " elements.");
alert("...and " + sups + " supervisors.");
writeConsole(supervisors, arrayLength, sups);
//window.open("new.htm", "new", "status=no toolbar=no resize=no scrollbars=yes width=300 height=200")
}
//new window stuff
function writeConsole(supervisors, arrayLength, sups) {
top.consoleRef=window.open('','myconsole', 'width=350,height=250' +',menubar=0' +',toolbar=1' +',status=0' +',scrollbars=1' +',resizable=1')
top.consoleRef.document.writeln( '<html><head><title>Console</title></head>' +'<body bgcolor=white onLoad="self.focus()"><b>Supervisor List<b><br>nuBody</body></html>' )
top.consoleRef.document.writeln( "<script language='javascript'>)");
top.consoleRef.document.writeln( "var count = 0");
top.consoleRef.document.writeln( "var supLast = ''");
top.consoleRef.document.writeln( "var supFirst = ''");
top.consoleRef.document.writeln( "var supCode = ''");
top.consoleRef.document.writeln( "for (count; count < sups; count += 3){");
top.consoleRef.document.writeln( "supLast = supervisors[count]");
top.consoleRef.document.writeln( "supFirst = supervisors[count+1]");
top.consoleRef.document.writeln( "supCode = supervisors[count+2]");
top.consoleRef.document.writeln( "top.consoleRef.document.writeln('supLast + supLast + supCode')");
top.consoleRef.document.writeln( "}</script>");
writeConsole(supervisors, arrayLength, sups);
top.consoleRef.document.close()
}
***********EDIT***********
Ok, nevermind. I figured out exactly how to do what I was attempting (although I still don't understand why the above was giving me a syntax error, so if anyone has an idea, feel free to post.) It turns out I was making it much more complicated than it really was. For anyone who's interested, here's what I did with that second function:
function writeConsole(supervisors, arrayLength, sups) {
top.consoleRef=window.open('','myconsole', 'width=350,height=250' +',menubar=0' +',toolbar=1' +',status=0' +',scrollbars=1' +',resizable=1')
top.consoleRef.document.writeln( '<html><head><title>Console</title></head>' +'<body bgcolor=white onLoad="self.focus()"><b>Supervisor List<b><br></body></html>' )
var count = 0;
var supLast = "";
var supFirst = "";
var supCode = "";
for (count; count < arrayLength; count += 3){
supLast = supervisors[count];
supFirst = supervisors[count+1];
supCode = supervisors[count+2];
top.consoleRef.document.writeln(supLast + ", " + supFirst + ": " + supCode + "<br>");
}
top.consoleRef.document.close()
}
function Parse(form){
alert("Parsing...");
var supervisors = new Array();
var nuBody = "";
supervisors = getSups();
alert(supervisors[0]);
var arrayLength = supervisors.length - 1;
var sups = arrayLength / 3;
alert("Array has " + arrayLength + " elements.");
alert("...and " + sups + " supervisors.");
writeConsole(supervisors, arrayLength, sups);
//window.open("new.htm", "new", "status=no toolbar=no resize=no scrollbars=yes width=300 height=200")
}
//new window stuff
function writeConsole(supervisors, arrayLength, sups) {
top.consoleRef=window.open('','myconsole', 'width=350,height=250' +',menubar=0' +',toolbar=1' +',status=0' +',scrollbars=1' +',resizable=1')
top.consoleRef.document.writeln( '<html><head><title>Console</title></head>' +'<body bgcolor=white onLoad="self.focus()"><b>Supervisor List<b><br>nuBody</body></html>' )
top.consoleRef.document.writeln( "<script language='javascript'>)");
top.consoleRef.document.writeln( "var count = 0");
top.consoleRef.document.writeln( "var supLast = ''");
top.consoleRef.document.writeln( "var supFirst = ''");
top.consoleRef.document.writeln( "var supCode = ''");
top.consoleRef.document.writeln( "for (count; count < sups; count += 3){");
top.consoleRef.document.writeln( "supLast = supervisors[count]");
top.consoleRef.document.writeln( "supFirst = supervisors[count+1]");
top.consoleRef.document.writeln( "supCode = supervisors[count+2]");
top.consoleRef.document.writeln( "top.consoleRef.document.writeln('supLast + supLast + supCode')");
top.consoleRef.document.writeln( "}</script>");
writeConsole(supervisors, arrayLength, sups);
top.consoleRef.document.close()
}
***********EDIT***********
Ok, nevermind. I figured out exactly how to do what I was attempting (although I still don't understand why the above was giving me a syntax error, so if anyone has an idea, feel free to post.) It turns out I was making it much more complicated than it really was. For anyone who's interested, here's what I did with that second function:
function writeConsole(supervisors, arrayLength, sups) {
top.consoleRef=window.open('','myconsole', 'width=350,height=250' +',menubar=0' +',toolbar=1' +',status=0' +',scrollbars=1' +',resizable=1')
top.consoleRef.document.writeln( '<html><head><title>Console</title></head>' +'<body bgcolor=white onLoad="self.focus()"><b>Supervisor List<b><br></body></html>' )
var count = 0;
var supLast = "";
var supFirst = "";
var supCode = "";
for (count; count < arrayLength; count += 3){
supLast = supervisors[count];
supFirst = supervisors[count+1];
supCode = supervisors[count+2];
top.consoleRef.document.writeln(supLast + ", " + supFirst + ": " + supCode + "<br>");
}
top.consoleRef.document.close()
}