Bugger

This is a discussion on "Bugger" within the JavaScript Forum section. This forum, and the thread "Bugger are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Aug 8th, 2006, 16:31
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Bugger

I have some javascript that generates a specified number of tables and populates each table with random numbers, this part works but I also have a header that says "BINGO" which I cannot get it to repeat. Any suggestions would be helpful. I have the table header stored in a string but when I do a document.write(str); or document.writeln(str); I get an error permission denied. So question is, what am I doing wrong. or is this just not possible?

The header looks like this:

Code: Select all
<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 class="heading">B</td><td class="heading">I</td><td class="heading">N</td><td class="heading">G</td><td class="heading">O</td></tr></table>
Snippet from the javascript:

Code: Select all
// Dynamically create rows and columns
    var tbl = document.all.tbl1;
    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);
        }
    }
__________________

Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)

Last edited by moojoo; Aug 8th, 2006 at 16:40.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Aug 8th, 2006, 21:12
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Bugger

How about starting each table with a header cell that goes the full width of the table and have/assign your 'BINGO' in/to that cell.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Aug 9th, 2006, 13:36
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: Bugger

That is the idea but the problem I am having is getting it to output that. when I try to output the string I get a permission denied error. So something is either out of place, incorrect, or I just did something silly.
__________________

Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)

Last edited by moojoo; Aug 9th, 2006 at 15:07.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Aug 9th, 2006, 16:49
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Bugger

Without seeing the code you tried to do this it's difficult to know.

In principle, adding nodes for the header cell should be no more problamatic than what you are already doing.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Aug 9th, 2006, 17:29
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: Bugger

Well yes but I am a javascript retard. But what you just said gave me a good idea of what I need to do.
__________________

Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Aug 9th, 2006, 17:46
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Bugger

Let us know how you get on.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Aug 10th, 2006, 16:13
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: Bugger

Here is the table heading I need to generate for each repeating instance: The question is, how would I turn the string into something I can use to repeat above every generated table? This is where I am having issues.

Code: Select all
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>';
and here is the javascript that generates the 5 x 5 tables with the random numbers: I have the heading table commented out at the moment.

Code: Select all
// 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);
        }
    }
__________________

Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Aug 15th, 2006, 15:27
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: Bugger

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>
__________________

Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)

Last edited by moojoo; Aug 15th, 2006 at 15:29.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
bugger

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 02:35.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42