Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts

    Question Whats wrong with my GetElementById

    Ok I can't figure out what I did wrong

    Code:
    //<![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

    Code:
    <!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>

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,078
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb

    Assuming the first part is the external file for this
    Code:
    <script type="text/javascript" src="js/lib.js" />
    add a </script> tag, like this:
    Code:
    <script type="text/javascript" src="js/lib.js" /></script>

  • #3
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by jmrker View Post
    Assuming the first part is the external file for this
    Code:
    <script type="text/javascript" src="js/lib.js" />
    add a </script> tag, like this:
    Code:
    <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

  • #4
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    You left out the quotation marks

    Code:
    document.getElementById(mainDiv).innerHTML = rpsComment1;
    
    	while(true) {
    
    		document.getElementById(mainDiv).innerHTML = rpsComment2;


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •