I feel like such a retard!

. For some reason Javascript is just beyond me damn my failed right brained logic. Here is my source as nasty as it is for this project. The tables repeat based on user input fine, I just can't get the damn header table to output at the top of each one. The
HTML at the bottom is the initial first table. The var str is the
html for the heading table stored in a variable which for some reason I can't figure out how to output:
- Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Bingo!</title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<link rel="stylesheet" href="style.css" media="screen" type="text/css" />
<link rel="stylesheet" href="print.css" media="print" type="text/css" />
</head>
<body>
<p>Use the form below to generate x amount of bingo cards.</p>
<script type="text/javascript">
document.write('<form name="generate"><input type=button value="Regenerate" onClick="gencards();"> <input type="text" name="printnumber" size="2" maxlength="3" /></form>')
function gencards() {
var genvalue = document.generate.printnumber.value
genvalue = genvalue -1;
for (i=0; i <= genvalue; i++){
var NROWS = 5; // Change this if you want a different number of rows/columns
var NCELLS = NROWS * NROWS;
var gbBingo = false;
if (BrowserCheck())
DoWork();
/////////////////////////////////////////////////////////////////////////////
// DoWork
// Main function to do work. Does the following:
// 1) Creates a MSXML DOMDocument object
// 2) Loads and parses 'MeetingBingo.xml'
// 3) Determines how many <Phrase> elements there are (nNodes)
// 4) Dynamically builds rows and columns in the <table>
// Ret: true if OK to proceed
/////////////////////////////////////////////////////////////////////////////
function DoWork()
{
var dom = new ActiveXObject("MSXML2.DOMDocument");
if (dom == null) {
window.alert("ERROR: Could not create DOM to parse XML.");
return(false);
}
dom.async = false;
dom.validateOnParse = true;
// Load the XML doc
if (!dom.load("MeetingBingo.xml")) {
var e = dom.parseError;
if (e.errorCode != 0)
window.alert("ERROR: Failed to load 'MeetingBingo.xml' data file.\n" + e.reason);
else
window.alert("ERROR: Failed to load 'MeetingBingo.xml' data file.\nUnknown error. Check syntax of document and try again.");
return(false);
}
dom.setProperty("SelectionLanguage", "XPath");
// Get the root element
var root = dom.selectSingleNode("MeetingBingo");
if (root == null) {
window.alert("ERROR: Cannot find <MeetingBingo> node.\nCheck syntax of document and try again.");
return(false);
}
// Determine total number of <Phrase> nodes
var nNodes = root.childNodes.length;
if (nNodes < NCELLS) {
window.alert("ERROR: Your 'MeetingBingo.xml' file has only " + nNodes + " <Phrase> elements.\nIt must have at least " + NCELLS + " <Phrase> elements to build the table.");
return(false);
}
// Dynamically create rows and columns
var tbl = document.all.tbl1;
var str = '<table id="tbl1" style="BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid" cellSpacing="0" cellPadding="0" border="0"><tr><td style="Font-weight:bold; color:#999900; font-size:2em;">B</td><td style="Font-weight:bold; color:#999900; font-size:2em;">I</td><td style="Font-weight:bold; color:#999900; font-size:2em;">N</td><td style="Font-weight:bold; color:#999900; font-size:2em;">G</td><td style="Font-weight:bold; color:#999900; font-size:2em;">O</td></tr></table>';
for (r = 0; r < NROWS; r++) {
var tr = tbl.insertRow();
for (c = 0; c < NROWS; c++) {
var tc = tr.insertCell();
tc.id = "Cell" + r + c;
// The number of nodes left
nNodes = root.childNodes.length;
// Generate random number
var nRand = Math.floor(Math.random() * nNodes) + 1;
// Pick out an element at random
var node = root.selectSingleNode("Phrase[" + nRand + "]");
if (node == null) {
window.alert("ERROR: Stupid programmer error: nRand = " + nRand + "\nnNodes = " + nNodes);
return(false);
}
// Set the Cell properties
tc.innerText = node.text;
// Remove the element from the DOM
root.removeChild(node);
}
}
return(true);
}
}
}
</script>
<table id="tbl1" style="BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid" cellSpacing="0" cellPadding="0" border="0"><tr><td style="Font-weight:bold; color:#999900; font-size:2em;">B</td><td style="Font-weight:bold; color:#999900; font-size:2em;">I</td><td style="Font-weight:bold; color:#999900; font-size:2em;">N</td><td style="Font-weight:bold; color:#999900; font-size:2em;">G</td><td style="Font-weight:bold; color:#999900; font-size:2em;">O</td></tr></table>
<script src="MeetingBingo.js" language="JScript"></script>
</body>
</html>