...

View Full Version : Problem with Javascript code not loading



alex@sadler.tk
05-14-2011, 11:31 AM
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:

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

bullant
05-14-2011, 01:24 PM
A couple of things that stand out.

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


<body onload="mainDo()">I haven't looked for other problems.

alex@sadler.tk
05-14-2011, 01:33 PM
Thank you!

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

And it works now!


Thanks Again!

Alex

bullant
05-14-2011, 01:41 PM
you're welcome :)

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum