...

View Full Version : Whats wrong with my GetElementById



MrEnder
01-18-2009, 12:31 AM
Ok I can't figure out what I did wrong :(



//<![CDATA[

var date = new Date();
var input = "";
var inputCheck = false;
var menu = "";
var br = "<br />";

var rpsP1 = "";
var rpsAI = "";

var menuComment1 = "1: Rock Papper Scissors" + br + "2: Craps" + br + br + "Type exit to quit";

var rpsComment1 = br + br + "Welcome to Rock Papper Scissors";
var rpsComment2 = br + "Type 1 for Rock, 2 for Scissors and 3 for Paper";

alert("1");

function getInput(input) {

input = ""

do {

inputCheck = false;

try {

input = prompt("Please enter in the info.","");

}
catch(ex) {

inputCheck = true;
alert("Bad input");

}

}while(inputCheck==true);

return input;

}

alert("2");

document.getElementById("mainDiv").innerHTML = menuComment1;

alert("3");

menu = getInput();

alert("4");

if(menu=="1") {

document.getElementById(mainDiv).innerHTML = rpsComment1;

while(true) {

document.getElementById(mainDiv).innerHTML = rpsComment2;


rpsAI = Math.random(Math.floor() *3);
rpsP1 = getInput();

break;


}

}



//]]>


this is the html



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<title>Jane Artificial Inteligence</title>

<link rel="stylesheet" type="text/css" href="css/template.css" />

<script type="text/javascript" src="js/lib.js" />


</head>
<body>

<div id="mainDiv">1</div>

</body>
</html>

jmrker
01-18-2009, 12:52 AM
Assuming the first part is the external file for this


<script type="text/javascript" src="js/lib.js" />

add a </script> tag, like this:


<script type="text/javascript" src="js/lib.js" /></script>

MrEnder
01-18-2009, 01:30 AM
Assuming the first part is the external file for this


<script type="text/javascript" src="js/lib.js" />

add a </script> tag, like this:


<script type="text/javascript" src="js/lib.js" /></script>


Nah the code has a self close on it. Its used in XHTML like <br /> so there is no need for a </script> it has a /> instead which works perfectly fine cause I do that all the time with no error the problem is with my GetElementById

ninnypants
01-18-2009, 01:40 AM
You left out the quotation marks



document.getElementById(mainDiv).innerHTML = rpsComment1;

while(true) {

document.getElementById(mainDiv).innerHTML = rpsComment2;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum