deerly Posted March 21, 2009 Share Posted March 21, 2009 Oh IE, you horrible pain! OK so I made a HangMan game and one of the functions is to display the "guessable" string with each letter character as _ and spaces as a paragraph break. This works fine in Firefox but doesn't work in IE. function displayWord(){ var thisString = ""; var splitWord = word.split(""); for (var i=0; i<word.length; i++){ if(revealedPool == true){ thisString += splitWord; } else{ if(splitWord != " "){ thisString += " _ "; } else if(splitWord == " "){ thisString += "<p>"; } } } document.getElementById("words").innerHTML = thisString; } The element it is supposed to be modifying is <p><span id="words" name="words"> </span> This works great in FF but while everything else seems to display OK in IE it won't show the word! The error it gives me is "unknown runtime error" Line: 144 (which is the innerHTML line seen above) Char: 3 Error: Unknown runtime error Code: 0 Thing is, if I hard code the values it works fine. Thanks so much for reading and helping shed some light on this! Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/ Share on other sites More sharing options...
Floydian Posted March 21, 2009 Share Posted March 21, 2009 I'm not sure, but I see a couple vars that look like they might be global variables. word revealedPool It could be the source of the problem, if they aren't defined. Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790131 Share on other sites More sharing options...
darkfreaks Posted March 21, 2009 Share Posted March 21, 2009 Fxed: function displayWord(){ var thisString = ""; var splitWord = word.split(""); for (var i=0; i<word.length; i++){ if(revealedPool === true){ thisString += splitWord; } else{ if(splitWord != " "){ thisString += " _ "; } else if(splitWord == " "){ thisString += "<p>"; } } } document.getElementById("words").innerHTML = thisString; } you were using == instead of the expected === Also as mentioned you do not define any of your variables so it throws undefined/not found errors. Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790284 Share on other sites More sharing options...
darkfreaks Posted March 21, 2009 Share Posted March 21, 2009 Fixed up more of the code so it stopps erroring for word since it is not a global function function displayWord(){ var thisString = "one two three four"; var splitWord = thisString.split(""); for (var i=0; i<thisString.length; i++){ if(revealedPool === true){ thisString += splitWord; } else{ if(splitWord != " "){ thisString += " _ "; } else if(splitWord == " "){ thisString += "<p>"; } } } document.getElementById("words").innerHTML = thisString; } Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790316 Share on other sites More sharing options...
darkfreaks Posted March 21, 2009 Share Posted March 21, 2009 cleaned up more: function displayWord(){ var thisString = ""; var splitWord = thisString.split(""); for (var i=0; i<splitWord.length; i++){ if(revealedPool === true){ thisString += splitWord; } else{ if(splitWord != " "){ thisString += " _ "; } else if(splitWord == " "){ thisString += "<p>"; } } } document.getElementById("words").innerHTML = thisString; } Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790326 Share on other sites More sharing options...
deerly Posted March 21, 2009 Author Share Posted March 21, 2009 Thank you so much darkfreaks!! Still having some problems though ??? In the first fix, the "_ _ _ _ " show up but there is no break for paragraphs for the spaces. Also, when I start to type the _ _ 's don't change to letters as it does in FireFox. (with the help of other functions) In the final fix it doesn't show up again. word and revealedPool are global variables and are defined by the time this function will be called. I know they are defined OK because even though the word doesn't show up, all of the other functions work correctly with the invisible word so I'll get (yes that's the right letter, oops already guessed that, no thast wrong) and the hangman will be hung! Something I just noticed... and I have NO IDEA how it works in FireFox! revealedPool is an array that is defined with every variable bool false! the idea is that when a letter is revealed the revealedPool[coresponding with the character in the string] will be set to true. Then it checks to see if it will display a _ if it hasnt been revealed or the letter if it has. I don't know how it was getting away with having just revealedPool instead of revealedPool but when i change it to the second suddenly it stops working in firefox! ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790392 Share on other sites More sharing options...
darkfreaks Posted March 21, 2009 Share Posted March 21, 2009 well if word and revealpool are predefined we are going to need the whole code. otherwise it is not going to work Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790438 Share on other sites More sharing options...
deerly Posted March 21, 2009 Author Share Posted March 21, 2009 Ok this is hm_js_functions.js document.onkeydown = keyHit; window.onload = initAll; var word; var type; //26 letters a-z var letterPool = new Array(25); //Remember to add 65 to get the letter unicode value var howHung = 0; var revealedPool = new Array(500); var endGame = false; function initAll(){ if(document.getElementById){ //document.getElementById("reload").onclick = anotherGallow; anotherGallow(); //newGallow(); } else{ alert("Your browser doesn't support this script. No hang-emo for you!"); } } function newGallow(){ alert(word); } function anotherGallow(){ for(var i=0; i<letterPool.length; i++){ letterPool = false; } for(var i=0; i<revealedPool.length; i++){ revealedPool = false; } howHung = 0; setWord();//Set the word as defined by PHP setType(); displayWord(); displayPool(); } function keyHit(evt){ if(!endGame){ if(evt){ var thisKey = evt.which; } else{ var thisKey = window.event.keyCode; } //alert(String.fromCharCode(thisKey)); if(thisKey >= 65 && thisKey <= 90){ birdSpeak("key"); tryLetter(thisKey); displayPool(); //alert(String.fromCharCode(thisKey)); } } } function tryLetter(guessed){ var poolKey = guessed - 65; //Check to see if the letter has already been guessed if(letterPool[poolKey]){ birdSpeak("alreadyGuessed"); birdReact("confused"); return; } else{ //Mark this letter as guessed. letterPool[poolKey] = true; var wasIn = false; //takes the letter the user guessed and checks to see if it is in the word string var splitWord = word.split(""); for(var i=0; i<word.length; i++){ if(splitWord.toLowerCase() == String.fromCharCode(guessed).toLowerCase()){ birdSpeak("right"); revealLetter(i); birdReact("happy"); wasIn = true; } } //if not, add a body part to hangman! if(!wasIn){ howHung += 1; birdReact("confused"); birdSpeak("wrong"); displayHanging(howHung) } } } function revealLetter(letter){ revealedPool[letter] = true; displayWord(); checkWin(); } function displayPool(){ var letter; var alphaBlock = ""; for(var i=0; i<=letterPool.length; i++){ if(!letterPool){ letter = i+65; alphaBlock += String.fromCharCode(letter); } } var alpha = document.getElementById("alpha"); alpha.innerHTML = alphaBlock; } //@param int number will be 1-7, which image to display //@param string type will determine which folder we look in for images (emo, baby, man, etc) function displayHanging(num){ //When an incorrect letter is guessed this function will be called to add //another piece of the hangman to the noose. 7 pieces total document.GALLOW.src="images/" + type + "/0" + num + ".gif"; checkLoss(num); } function displayWord(){ var thisString = ""; var splitWord = thisString.split(""); for (var i=0; i<splitWord.length; i++){ if(revealedPool){ thisString += splitWord; } else{ if(splitWord != " "){ thisString += " _ "; } else if(splitWord == " "){ thisString += "<p>"; } } } document.getElementById("words").innerHTML = thisString; } function checkWin(){ //Check to see if all of the letters in word have been revealed var splitWord = word.split(""); var didWin = 0; for (var i=0; i<word.length; i++){ if(splitWord != " "){ if(!revealedPool){ didWin += 1; } } } if(didWin == 0){ gameOver("won"); } } function checkLoss(num){ if(num >= 7){ gameOver("lose"); } } function gameOver(result){//result is either win or lose //If the hangman is hung (reaches 7 pieces) the game is over //Display the word with all letters revealed //Show some kind of failure message //Invite to create a new game if(result == "won"){ birdSpeak("win"); birdReact("happy"); } else if(result == "lose"){ for (var i=0; i<word.length; i++){ revealedPool = true; } displayWord(); birdSpeak("lose"); birdReact("sad"); } endGame = true; } function birdSpeak(action){ if(action == "lose"){ document.getElementById("birdWord").innerHTML = "You lost "; } else if(action == "win"){ document.getElementById("birdWord").innerHTML = "You won "; } else if(action == "alreadyGuessed"){ document.getElementById("birdWord").innerHTML = "Oops, you have already guessed this letter!"; } else if(action == "key"){ document.getElementById("birdWord").innerHTML = "What could it be?"; } else if(action == "wrong"){ document.getElementById("birdWord").innerHTML = "Uh-oh, wrong letter"; } else if(action == "right"){ document.getElementById("birdWord").innerHTML = "Good job, that was a correct letter!"; } } function birdReact(action){ if(action == "happy"){ document.getElementById("header-bird").style.backgroundImage='url(images/lark/happy.gif)'; } else if(action == "sad"){ document.getElementById("header-bird").style.backgroundImage='url(images/lark/sad.gif)'; } else if(action == "confused"){ document.getElementById("header-bird").style.backgroundImage='url(images/lark/confused.gif)'; } } The set word and set type functions are within the .php page because they need to use PHP variables. game playing page <html> <body> <?php require_once("hm_class.inc.php"); db::connect(); if(isset($_GET['g'])){ $game_in = (int)$_GET['g']; $hint = hangman::getGameHint($game_in); $word = hangman::getGameGuessable($game_in); $type = hangman::getGameType($game_in); } ?> <script language="javascript" type="text/javascript"> function setWord(){ word = "<?php echo $word; ?>"; } function setType(){ type = "<?php echo $type; ?>"; } </script> <LINK href="style.css" rel="stylesheet" type="text/css"> <script type = "text/javascript" src="hm_js_functions.js"></script> <div id="body-center"> <div id="body"> <div id="header"> <div id="header-bird"> </div> <div id="header-bird-words"> <span id="birdWord" name="birdWord">What could it be?</span> </div> <div id="header-hint"> <span name="hint" id="hint"><h2> <?php if(isset($hint)){ echo"$hint"; } ?> </h2></span> </div> </div> <div id="middle"> <div id="middle-words"> <p><span id="words" name="words"> </span> </div> <div id="middle-gallow"> <img id="GALLOW" name="GALLOW" src="images/gallow.gif"> </div> <div id="middle-alpha"> <div name="alpha" id="alpha"> </div> </div> </div> </div> <div id="bottom"> Enjoying your game of hang-<?php echo"$type";?>? <br><a href="hangman.php">Send a custom hang-man game to one of your friends!</a> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790442 Share on other sites More sharing options...
darkfreaks Posted March 21, 2009 Share Posted March 21, 2009 Line 89 Missing Semicolon Solution: ; line 36 and 37: settype(),setword() not found line 122: constructor or instance GALLOW not found line 192 & 212: action is a reserved DOM word Solution: change action to actions Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790449 Share on other sites More sharing options...
deerly Posted March 21, 2009 Author Share Posted March 21, 2009 Thank you so much for your patience I oughta buy you a beer! OK so here is what I have right now for the .js file document.onkeydown = keyHit; window.onload = initAll; var word; var type; //26 letters a-z var letterPool = new Array(25); //Remember to add 65 to get the letter unicode value var howHung = 0; var revealedPool = new Array(500); var endGame = false; function initAll(){ if(document.getElementById){ //document.getElementById("reload").onclick = anotherGallow; anotherGallow(); //newGallow(); } else{ alert("Your browser doesn't support this script. No hang-emo for you!"); } } function newGallow(){ alert(word); } function anotherGallow(){ for(var i=0; i<letterPool.length; i++){ letterPool = false; } for(var i=0; i<revealedPool.length; i++){ revealedPool = false; } howHung = 0; setWord();//Set the word as defined by PHP setType(); displayWord(); displayPool(); } function keyHit(evt){ if(!endGame){ if(evt){ var thisKey = evt.which; } else{ var thisKey = window.event.keyCode; } //alert(String.fromCharCode(thisKey)); if(thisKey >= 65 && thisKey <= 90){ birdSpeak("key"); tryLetter(thisKey); displayPool(); //alert(String.fromCharCode(thisKey)); } } } function tryLetter(guessed){ var poolKey = guessed - 65; //Check to see if the letter has already been guessed if(letterPool[poolKey]){ birdSpeak("alreadyGuessed"); birdReact("confused"); return; } else{ //Mark this letter as guessed. letterPool[poolKey] = true; var wasIn = false; //takes the letter the user guessed and checks to see if it is in the word string var splitWord = word.split(""); for(var i=0; i<word.length; i++){ if(splitWord.toLowerCase() == String.fromCharCode(guessed).toLowerCase()){ birdSpeak("right"); revealLetter(i); birdReact("happy"); wasIn = true; } } //if not, add a body part to hangman! if(!wasIn){ howHung += 1; birdReact("confused"); birdSpeak("wrong"); displayHanging(howHung); } } } function revealLetter(letter){ revealedPool[letter] = true; displayWord(); checkWin(); } function displayPool(){ var letter; var alphaBlock = ""; for(var i=0; i<=letterPool.length; i++){ if(!letterPool){ letter = i+65; alphaBlock += String.fromCharCode(letter); } } var alpha = document.getElementById("alpha"); alpha.innerHTML = alphaBlock; } //@param int number will be 1-7, which image to display //@param string type will determine which folder we look in for images (emo, baby, man, etc) function displayHanging(num){ //When an incorrect letter is guessed this function will be called to add //another piece of the hangman to the noose. 7 pieces total document.GALLOW.src="images/" + type + "/0" + num + ".gif"; checkLoss(num); } function displayWord(){ var thisString = ""; var splitWord = word.split(""); for (var i=0; i<word.length; i++){ if(revealedPool == true){ thisString += splitWord; } else{ if(splitWord != " "){ thisString += " _ "; } else if(splitWord == " "){ thisString += "<p>"; } } } document.getElementById("words").innerHTML = thisString; } function checkWin(){ //Check to see if all of the letters in word have been revealed var splitWord = word.split(""); var didWin = 0; for (var i=0; i<word.length; i++){ if(splitWord != " "){ if(!revealedPool){ didWin += 1; } } } if(didWin == 0){ gameOver("won"); } } function checkLoss(num){ if(num >= 7){ gameOver("lose"); } } function gameOver(result){//result is either win or lose //If the hangman is hung (reaches 7 pieces) the game is over //Display the word with all letters revealed //Show some kind of failure message //Invite to create a new game if(result == "won"){ birdSpeak("win"); birdReact("happy"); } else if(result == "lose"){ for (var i=0; i<word.length; i++){ revealedPool = true; } displayWord(); birdSpeak("lose"); birdReact("sad"); } endGame = true; } function birdSpeak(actions){ if(actions == "lose"){ document.getElementById("birdWord").innerHTML = "You lost "; } else if(actions == "win"){ document.getElementById("birdWord").innerHTML = "You won "; } else if(actions == "alreadyGuessed"){ document.getElementById("birdWord").innerHTML = "Oops, you have already guessed this letter!"; } else if(actions == "key"){ document.getElementById("birdWord").innerHTML = "What could it be?"; } else if(actions == "wrong"){ document.getElementById("birdWord").innerHTML = "Uh-oh, wrong letter"; } else if(actions == "right"){ document.getElementById("birdWord").innerHTML = "Good job, that was a correct letter!"; } } function birdReact(actions){ if(actions == "happy"){ document.getElementById("header-bird").style.backgroundImage='url(images/lark/happy.gif)'; } else if(actions == "sad"){ document.getElementById("header-bird").style.backgroundImage='url(images/lark/sad.gif)'; } else if(actions == "confused"){ document.getElementById("header-bird").style.backgroundImage='url(images/lark/confused.gif)'; } } Everything works perfectly in FF and everything works in IE *except* the "guessable message" will not display. setWord() and setType() do seem to work within the game play page because in both FF and IE the hangman being displayed (with wrong selections) is correct and even in IE it does know what word is being played with because it knows what is a right/wrong letter, changes hangman image accordingly and can detect wins/losses. It now does not display any JS error in IE that I can see, it just does not display the words. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790481 Share on other sites More sharing options...
darkfreaks Posted March 21, 2009 Share Posted March 21, 2009 Fixed used === instead of == : document.onkeydown = keyHit; window.onload = initAll; var word; var type; //26 letters a-z var letterPool = new Array(25); //Remember to add 65 to get the letter unicode value var howHung = 0; var revealedPool = new Array(500); var endGame = false; function initAll(){ if(document.getElementById){ //document.getElementById("reload").onclick = anotherGallow; anotherGallow(); //newGallow(); } else{ alert("Your browser doesn't support this script. No hang-emo for you!"); } } function newGallow(){ alert(word); } function anotherGallow(){ for(var i=0; i<letterPool.length; i++){ letterPool = false; } for(var i=0; i<revealedPool.length; i++){ revealedPool = false; } howHung = 0; setWord();//Set the word as defined by PHP setType(); displayWord(); displayPool(); } function keyHit(evt){ if(!endGame){ if(evt){ var thisKey = evt.which; } else{ var thisKey = window.event.keyCode; } //alert(String.fromCharCode(thisKey)); if(thisKey >= 65 && thisKey <= 90){ birdSpeak("key"); tryLetter(thisKey); displayPool(); //alert(String.fromCharCode(thisKey)); } } } function tryLetter(guessed){ var poolKey = guessed - 65; //Check to see if the letter has already been guessed if(letterPool[poolKey]){ birdSpeak("alreadyGuessed"); birdReact("confused"); return; } else{ //Mark this letter as guessed. letterPool[poolKey] = true; var wasIn = false; //takes the letter the user guessed and checks to see if it is in the word string var splitWord = word.split(""); for(var i=0; i<word.length; i++){ if(splitWord.toLowerCase() == String.fromCharCode(guessed).toLowerCase()){ birdSpeak("right"); revealLetter(i); birdReact("happy"); wasIn = true; } } //if not, add a body part to hangman! if(!wasIn){ howHung += 1; birdReact("confused"); birdSpeak("wrong"); displayHanging(howHung); } } } function revealLetter(letter){ revealedPool[letter] = true; displayWord(); checkWin(); } function displayPool(){ var letter; var alphaBlock = ""; for(var i=0; i<=letterPool.length; i++){ if(!letterPool){ letter = i+65; alphaBlock += String.fromCharCode(letter); } } var alpha = document.getElementById("alpha"); alpha.innerHTML = alphaBlock; } //@param int number will be 1-7, which image to display //@param string type will determine which folder we look in for images (emo, baby, man, etc) function displayHanging(num){ //When an incorrect letter is guessed this function will be called to add //another piece of the hangman to the noose. 7 pieces total document.GALLOW.src="images/" + type + "/0" + num + ".gif"; checkLoss(num); } function displayWord(){ var thisString = ""; var splitWord = word.split(""); for (var i=0; i<word.length; i++){ if(revealedPool === true){ thisString += splitWord; } else{ if(splitWord != " "){ thisString += " _ "; } else if(splitWord == " "){ thisString += "<p>"; } } } document.getElementById("words").innerHTML = thisString; } function checkWin(){ //Check to see if all of the letters in word have been revealed var splitWord = word.split(""); var didWin = 0; for (var i=0; i<word.length; i++){ if(splitWord != " "){ if(!revealedPool){ didWin += 1; } } } if(didWin === 0){ gameOver("won"); } } function checkLoss(num){ if(num >= 7){ gameOver("lose"); } } function gameOver(result){//result is either win or lose //If the hangman is hung (reaches 7 pieces) the game is over //Display the word with all letters revealed //Show some kind of failure message //Invite to create a new game if(result === "won"){ birdSpeak("win"); birdReact("happy"); } else if(result === "lose"){ for (var i=0; i<word.length; i++){ revealedPool = true; } displayWord(); birdSpeak("lose"); birdReact("sad"); } endGame = true; } function birdSpeak(actions){ if(actions == "lose"){ document.getElementById("birdWord").innerHTML = "You lost "; } else if(actions === "win"){ document.getElementById("birdWord").innerHTML = "You won "; } else if(actions ==="alreadyGuessed"){ document.getElementById("birdWord").innerHTML = "Oops, you have already guessed this letter!"; } else if(actions === "key"){ document.getElementById("birdWord").innerHTML = "What could it be?"; } else if(actions === "wrong"){ document.getElementById("birdWord").innerHTML = "Uh-oh, wrong letter"; } else if(actions === "right"){ document.getElementById("birdWord").innerHTML = "Good job, that was a correct letter!"; } } function birdReact(actions){ if(actions === "happy"){ document.getElementById("header-bird").style.backgroundImage='url(images/lark/happy.gif)'; } else if(actions === "sad"){ document.getElementById("header-bird").style.backgroundImage='url(images/lark/sad.gif)'; } else if(actions === "confused"){ document.getElementById("header-bird").style.backgroundImage='url(images/lark/confused.gif)'; } } Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790485 Share on other sites More sharing options...
deerly Posted March 21, 2009 Author Share Posted March 21, 2009 Not yet :-\ in IE I get the error: Line 77 Char 14 Error: Object doesn't support this property or method Code: 0 It displays a line of "_ _ _ _ _ _ _ _ _ " with no <p> where the space is. Does not react to key strokes at all. Same problem in firefox and IE. In FF I get the error: splitWord.toLowerCase is not a function tryLetter(66)hm_js_fu...ctions.js (line 76) keyHit(keydown charCode=0, keyCode=66)hm_js_fu...ctions.js (line 54) [break on this error] if(splitWord.toLowerCase() ...ng.fromCharCode(guessed).toLowerCase()){ :-\ Edit: the test phrase I am using is "Biggest Loser" which should display as _ _ _ _ _ _ _ _ _ _ _ _ When it starts. Then when correct letters are guessed they are filled in appropriately. Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790490 Share on other sites More sharing options...
darkfreaks Posted March 21, 2009 Share Posted March 21, 2009 Here is what this “toLowerCase() not a function error” really means: The object you’re trying to lowercase is NOT a string object. By using alert(typeof(object)); you can determine what type the JavaScript engine thinks the object is. A simple solution is: object.toString().toLowerCase; Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790496 Share on other sites More sharing options...
deerly Posted March 21, 2009 Author Share Posted March 21, 2009 Changing line 76 to: if(splitWord.toString().toLowerCase() == String.fromCharCode(guessed).toLowerCase()){ Seems to have stopped the error messages but it's still having issues displaying the word and now a bunch of new ones: http://larkingabout.com/projects/HangMan/layout.php?g=111 The bird isn't reacting properly and telling you you've already guessed letters and when you loose and it displays the word it just repeats the string over and over again with commas. Also, the alphabet pool is no longer displaying at all It is frustrating because while I can see all of these mistakes I made, it was working in FF and now it's got all these issues that came from fixing it ??? Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790505 Share on other sites More sharing options...
darkfreaks Posted March 21, 2009 Share Posted March 21, 2009 this pops up in firebug: Permission Denied to call method: Location.tostring Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790522 Share on other sites More sharing options...
deerly Posted March 21, 2009 Author Share Posted March 21, 2009 Phew! Ok Thank you for your help, I have it working again in FF but the same problem in IE! document.onkeydown = keyHit; window.onload = initAll; var word; var type; //26 letters a-z var letterPool = new Array(25); //Remember to add 65 to get the letter unicode value var howHung = 0; var revealedPool = new Array(500); var endGame = false; function initAll(){ if(document.getElementById){ //document.getElementById("reload").onclick = anotherGallow; anotherGallow(); //newGallow(); } else{ alert("Your browser doesn't support this script. No hang-" + type + " for you!"); } } function newGallow(){ alert(word); } function anotherGallow(){ for(var i=0; i<letterPool.length; i++){ letterPool = false; } for(var i=0; i<revealedPool.length; i++){ revealedPool = false; } howHung = 0; setWord();//Set the word as defined by PHP setType(); displayPool(); displayWord(); } function keyHit(evt){ if(!endGame){ if(evt){ var thisKey = evt.which; } else{ var thisKey = window.event.keyCode; } //alert(String.fromCharCode(thisKey)); if(thisKey >= 65 && thisKey <= 90){ birdSpeak("key"); tryLetter(thisKey); displayPool(); //alert(String.fromCharCode(thisKey)); } } } function tryLetter(guessed){ var poolKey = guessed - 65; //Check to see if the letter has already been guessed if(letterPool[poolKey]){ birdSpeak("alreadyGuessed"); birdReact("confused"); return; } else{ //Mark this letter as guessed. letterPool[poolKey] = true; var wasIn = false; //takes the letter the user guessed and checks to see if it is in the word string var splitWord = word.split(""); for(var i=0; i<word.length; i++){ if(splitWord.toString().toLowerCase() == String.fromCharCode(guessed).toLowerCase()){ birdSpeak("right"); revealLetter(i); birdReact("happy"); wasIn = true; } } //if not, add a body part to hangman! if(!wasIn){ howHung += 1; birdReact("confused"); birdSpeak("wrong"); displayHanging(howHung); } } } function revealLetter(letter){ revealedPool[letter] = true; displayWord(); checkWin(); } function displayPool(){ var letter; var alphaBlock = ""; for(var i=0; i<=letterPool.length; i++){ if(!letterPool){ letter = i+65; alphaBlock += String.fromCharCode(letter); } } var alpha = document.getElementById("alpha"); alpha.innerHTML = alphaBlock; } //@param int number will be 1-7, which image to display //@param string type will determine which folder we look in for images (emo, baby, man, etc) function displayHanging(num){ //When an incorrect letter is guessed this function will be called to add //another piece of the hangman to the noose. 7 pieces total document.GALLOW.src="images/" + type + "/0" + num + ".gif"; checkLoss(num); } function displayWord(){ var thisString = ""; var splitWord = word.split(""); for (var i=0; i<word.length; i++){ if(revealedPool === true){ thisString += splitWord; } else{ if(splitWord != " "){ thisString += " _ "; } else if(splitWord == " "){ thisString += "<p>"; } } } document.getElementById("words").innerHTML = thisString; } function checkWin(){ //Check to see if all of the letters in word have been revealed var splitWord = word.split(""); var didWin = 0; for (var i=0; i<word.length; i++){ if(splitWord != " "){ if(!revealedPool){ didWin += 1; } } } if(didWin === 0){ gameOver("won"); } } function checkLoss(num){ if(num >= 7){ gameOver("lose"); } } function gameOver(result){//result is either win or lose //If the hangman is hung (reaches 7 pieces) the game is over //Display the word with all letters revealed //Show some kind of failure message //Invite to create a new game if(result === "won"){ birdSpeak("win"); birdReact("happy"); } else if(result === "lose"){ for (var i=0; i<word.length; i++){ revealedPool = true; } document.getElementById("words").innerHTML = word; birdSpeak("lose"); birdReact("sad"); } endGame = true; } function birdSpeak(actions){ if(actions == "lose"){ document.getElementById("birdWord").innerHTML = "You lost "; } else if(actions === "win"){ document.getElementById("birdWord").innerHTML = "You won "; } else if(actions ==="alreadyGuessed"){ document.getElementById("birdWord").innerHTML = "Oops, you have already guessed this letter!"; } else if(actions === "key"){ document.getElementById("birdWord").innerHTML = "What could it be?"; } else if(actions === "wrong"){ document.getElementById("birdWord").innerHTML = "Uh-oh, wrong letter"; } else if(actions === "right"){ document.getElementById("birdWord").innerHTML = "Good job, that was a correct letter!"; } } function birdReact(actions){ if(actions === "happy"){ document.getElementById("header-bird").style.backgroundImage='url(images/lark/happy.gif)'; } else if(actions === "sad"){ document.getElementById("header-bird").style.backgroundImage='url(images/lark/sad.gif)'; } else if(actions === "confused"){ document.getElementById("header-bird").style.backgroundImage='url(images/lark/confused.gif)'; } } What is interesting is that it wouldn't display the alphabet pool until I moved the displayPool() above the displayWord() on lines 38 and 39. Makes me think there is something wrong with the displayWord() function still. Otherwise it seems to be working again though, thank goodness! http://larkingabout.com/projects/HangMan/layout.php?g=111 Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790533 Share on other sites More sharing options...
darkfreaks Posted March 21, 2009 Share Posted March 21, 2009 ok i have the IE Tab for firefox and this just popped up ??? [object HTMLSpanElement] Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790559 Share on other sites More sharing options...
deerly Posted March 21, 2009 Author Share Posted March 21, 2009 Sorry I was trying different things. It seems like the problem is that IE doesn't like the var thisString and doesn't see it as anything. Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790563 Share on other sites More sharing options...
darkfreaks Posted March 21, 2009 Share Posted March 21, 2009 can you post your current code inside the code here tags ??? Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790564 Share on other sites More sharing options...
deerly Posted March 21, 2009 Author Share Posted March 21, 2009 I got it!! The problem was that IE wasn't recognizing the "<p>" and switching it to <br> worked fine. I guess because there was no closing tag? Phew, thank you so much for your patience and help! How can I mark this as solved? Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790566 Share on other sites More sharing options...
darkfreaks Posted March 22, 2009 Share Posted March 22, 2009 most likely the solved button is in the lower left corner Quote Link to comment https://forums.phpfreaks.com/topic/150437-solved-js-in-ie-unknown-runtime-error/#findComment-790603 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.