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
    New to the CF scene
    Join Date
    May 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Problem with Javascript code not loading

    Hello everyone,

    I am just beginning to learn javascript, and I am trying to create a little game where when a user hovers over a picture it changes, and things like that.

    At the moment I have been trying to make it so that the pictures tile so they fill the whole page area, dynamically so that it changes depending on the users browser size (px). The images have many attributes so I can't just tile them with css as they need to be actual elements.

    The problem is the code doesn't run, and I can't work out why. I think all the lines that require it have semi colons and its all correct.

    Forgive me if the answer is clear but as I said I only just started learning.

    Anyway, on with the code:
    Code:
    <!doctype html>
    <html lang="en">
    <head>
    <title>Hi, I'm a button.</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <script type="javascript">
    	function mainDo() {
    	if (document.body && document.body.offsetWidth) {
    		winW = document.body.offsetWidth;
    		winH = document.body.offsetHeight;
    	}
    	if (document.compatMode=='CSS1Compat' && document.documentElement && document.documentElement.offsetWidth ) {
    		winW = document.documentElement.offsetWidth;
    		winH = document.documentElement.offsetHeight;
    	}
    	if (window.innerWidth && window.innerHeight) {
    		winW = window.innerWidth;
    		winH = window.innerHeight;
    	}
    	document.write('Width = ' + winW + 'Height = ' + winH);
    	winW=winW/127;
    	winH=winH/128;
    	winW=Math.round(winW);
    	winWs=winW;
    	winH=Math.round(winH);
    	winHs=winH;
    	document.write('Width = ' + winW + 'Height = ' + winH);
    	while (winH>0) {
    		while (winW>0) {
    		document.write('<img onMouseover="this.src=\'img/hibutton_orange.png\'" onClick="this.src=\'img/hibutton_green.png\'" ondblClick="this.src=\'img/hibutton_blue.png\'" src="img/hibutton_blue.png">');
    		winW=winW-1;
    		}
    		document.write('\n' + '<br>');
    		winW=winWs;
    		winH=winH-1;
    	}
    	}
    </script>
    </head>
    <body onload="maindo()">
    </body>
    </html>

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    A couple of things that stand out.

    1)
    Code:
    <script type="text/javascript">
    2) javascript is case sensitive.

    Code:
    <body onload="mainDo()">
    I haven't looked for other problems.
    Last edited by bullant; 05-14-2011 at 02:26 PM.

  • Users who have thanked bullant for this post:

    alex@sadler.tk (05-14-2011)

  • #3
    New to the CF scene
    Join Date
    May 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you!

    You can tell I'm a beginner with mistakes like that.

    And it works now!


    Thanks Again!

    Alex

  • #4
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    you're welcome

    and everyone, whether they admit it or not, was a beginner at some stage .


  •  

    Tags for this Thread

    Posting Permissions

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