I'm just starting Javascript, and I'm writing a beginner program in MS notepad and whenever I try to open it it gives me an error saying,
Line: 1
Char: 1
Error: Syntax error
Code: 800A03EA
Source: Microsoft JScript compilation error
My script is:
<!DOCTYPE html> <html> <body> <script> function changeImage() { element=document.getElementById('myimage') if (element.src.match("bulbon")) { element.src="pic_bulboff.gif"; } else { element.src="pic_bulbon.gif"; } }function displayDate() { document.getElementById("demo").innerHTML=Date(); } </script> <img id="myimage" onclick="changeImage()" src="pic_bulboff.gif" width="100" height="180"> <p id="demo">Click the light bulb to turn on/off the light</p> <button type="button" onclick="displayDate()">Display Date</button> </body> </html>
Last edited by owlman (2012-10-10 18:17:57)
Offline
The problem is that I don't think the !DOCTYPE tag allows 'html' in it, try without it.
Offline
TorbyFork234 wrote:
The problem is that I don't think the !DOCTYPE tag allows 'html' in it, try without it.
<!DOCTYPE html> is fine, it declares a html5 document.
I see though that your function declaration is incorrect.
var changeImage = function() {
statement;
statement;
};
Don't forget the semicolon right and the end either.
Offline
jji7skyline wrote:
TorbyFork234 wrote:
The problem is that I don't think the !DOCTYPE tag allows 'html' in it, try without it.
<!DOCTYPE html> is fine, it declares a html5 document.
I see though that your function declaration is incorrect.
var changeImage = function() {
statement;
statement;
};
Don't forget the semicolon right and the end either.
You can declare it his way too...
Offline
MathWizz wrote:
jji7skyline wrote:
TorbyFork234 wrote:
The problem is that I don't think the !DOCTYPE tag allows 'html' in it, try without it.
<!DOCTYPE html> is fine, it declares a html5 document.
I see though that your function declaration is incorrect.
var changeImage = function() {
statement;
statement;
};
Don't forget the semicolon right and the end either.You can declare it his way too...
You're right! I wonder what's the difference
Offline
Ok, I've made a html of your code, then put images for the bulbon and bulboff, and it works fine.
Here's the code I used.
<!DOCTYPE html> <html> <body> <script> function changeImage() { element=document.getElementById('myimage') if (element.src.match("bulbon")) { element.src="pic_bulboff.jpg"; } else { element.src="pic_bulbon.jpg"; } }function displayDate() { document.getElementById("demo").innerHTML=Date(); } </script> <img id="myimage" onclick="changeImage()" src="pic_bulboff.jpg" width="100" height="180"> <p id="demo">Click the light bulb to turn on/off the light</p> <button type="button" onclick="displayDate()">Display Date</button> </body> </html>
Notice I have pic_bulbon.jpg, since I used jpgs from Google Images for testing it.
Last edited by jji7skyline (2012-10-10 21:01:24)
Offline
I also fiddled around with it a bit... http://jsfiddle.net/Kz4fj/
Note: Mine might be a little more crazy for a beginner. I got carried away. xD
Offline
owlman wrote:
It gave me the exact same error, even with the exact same error code and stuff.
Your Microsoft compiler is wrong. Plus, JS doesn't need to be compiled, it's an interpreted language.
Just make a html file of your code and go
Offline
jji7skyline wrote:
owlman wrote:
It gave me the exact same error, even with the exact same error code and stuff.
Your Microsoft compiler is wrong. Plus, JS doesn't need to be compiled, it's an interpreted language.
Just make a html file of your code and go
It works but the bulb images are showing up as the broken image icon.
Offline
Try replacing your images links with these.
Bulb on: http://i.imgur.com/5mNC1.jpg
Bulb off: http://i.imgur.com/gQFXG.jpg
Offline
Congrats! What exactly is a .hta file?
Offline