Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
October 31, 2014, 06:38:00 PM

Pages: [1]   Go Down
  Print  
Author Topic: innerHTML & Firefox  (Read 3210 times)
Jim Aikin
Newbie
*
Offline Offline

Posts: 5


« on: February 05, 2008, 11:02:19 AM »

Still in the very beginning stages of learning JavaScript, I've created a random haiku generator. This uses an external .js file to generate the actual text. It works as expected in IE7, but doesn't work in FireFox 2. (Yes, JavaScript is enabled in FF.) I suspect the problem is with innerHTML (or possibly with how I'm loading the external file). I've poked around on the Web and haven't found any clues, so here I am. Code follows -- suggestions appreciated!

--Jim Aikin

// begin main page code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
  <head><title>Test Page</title>
  <script type="text/javascript" src="lineGenerator.js">
  </script>
 
  </head>
  <body>
    <div id="Line1"><p>g </div>
    <div id="Line2"><p>f </div>
    <div id="Line3"><p>d </div>
    <div id="randomNum">
      <script type="text/javascript">
    new function randomizeLine (lineNum) {
    var lineText;
    switch(lineNum) {
    case 1:
        lineText = generateLine(1);
        document.getElementById('Line1').innerHTML = lineText;
        break;
    case 2:
        lineText = generateLine(2);
        document.getElementById('Line2').innerHTML = lineText;
        break;
    case 3:
        lineText = generateLine(3);
        document.getElementById('Line3').innerHTML = lineText;
    }
  }
  new function randomizeAll() {
    randomizeLine(1);
    randomizeLine(2);
    randomizeLine(3);
    }
    onload = "randomizeAll();"
    </script>
    <noscript>
      Either your browser does not support JavaScript, or you have turned it off.
    </noscript>
    </div>

    <form>
    <input type="button" name="Line1" value="Line 1" onClick="randomizeLine(1)"; />
    <input type="button" name="Line2" value="Line 2" onClick="randomizeLine(2)"; />
    <input type="button" name="Line3" value="Line 3" onClick="randomizeLine(3)"; />
    <br><br>
    <input type="button" name="AllNew" value="Regenerate All" onClick="randomizeAll()"; />
    </form>
  </body>
</html>

//end main page code -- begin external file code

function generateLine(lineNum) {
var randNum = Math.ceil(4*Math.random());
var lineText;

if (lineNum == 1)
    switch(randNum) {
        case 1:
        lineText = "In the white morning";
        break;
        case 2:
        lineText = "Along a river";
        break;
        case 3:
        lineText = "Behind the cottage";
        break;
        default:
        lineText = "When deep night arrives";
    }
if (lineNum == 2)
    switch(randNum) {
        case 1:
        lineText = "I tread carefully, choosing";
        break;
        case 2:
        lineText = "the stone statues fall backward";
        break;
        case 3:
        lineText = "a young boy weeps and plays dice";
        break;
        default:
        lineText = "monkeys dance like dervishes";
    }
if (lineNum == 3)
    switch(randNum) {
        case 1:
        lineText = "without knowing it.";
        break;
        case 2:
        lineText = "as the bright moon weeps.";
        break;
        case 3:
        lineText = "while flutes trill for days.";
        break;
        default:
        lineText = "despite the barricade.";
    }
     
return lineText;
}

// end external file code
Logged
scanman20
Senior Moderator
▄ber Jedi
*****
Offline Offline

Posts: 1545



WWW
« Reply #1 on: February 05, 2008, 02:16:20 PM »

Take the "new" out before your functions. Not the correct usage.
Logged

Even a broken clock is right twice a day.
NotOneBit.com
MCSE - MCSA - MCP
Pages: [1]   Go Up
  Print  
 
Jump to: