hey guys, Now that I have done my SCJP exam, I now am doing JavaScript, and because you guys are a great source of help, i thought i would bring my problem to you. you se I have done a few tutorials on JavaScript 1.2 and I was told that the <SCRIPT> should be in the <HEAD> tags. here is a copy of my HTML file with a bit of JavaScript in it. I copied it from the tutorial, so I guess it should work, but it don't work on my browser: which I have Internet Explorer 6.0 as default, and Mozill 1.6, both don't show anything.
I was told, I don't need to declare variables with var, but just to make it easier for debugging purposes, something like that. I also don't know about the use of the semi colon, in some of the tutorial it said you needed it, and in parts it did not, if I used them on an online test, (distance learning) it said i got it wrong. I have asked my distance learning course to answer the same, but they are taking their time. I hope you can help me out. thanks Davy p.s. I found java easier to understand
JavaScript can be a weird experience if you are used to the completely deterministic nature of Java. It's interpretive nature means you can do some wonderous (and scary) things, but it's definitely in a different world. 1) var When you declare variables with var, they become declared on the window object. But since variables will be auto-declared on their first use, and the window object is the 'default' implicit object in an HTML page, the effect of leaving off the var is the pretty much the same as using it. But that doesn't mean you shouldn't. Just because you can be lazy, doesn't mean you should be. For readability if nothing else, I always use the var. 2) semi-colons Yes, you can leave them off if the interpreter can figure out that you should have put one there in the first palce. Again, just put the semi-colons in like they should be. If you are used to Java, this is more natural anyway. 3) head While Javascript you want interpreted prior to the body should go in the head, you can place script tags throughout the page. You will see a lot of sites out there that build up conditional portions of the page using document.write in script tags sprinkled throughout the page. (Since I write mostly in JSPs, I usually handle this sort of thing on the server side, but this client-side technique is often used when no server-side technology is being employed). The 'written' content appears in the place where the script tag is declared.
If you want good information on JavaScript for tag reference or tutorails I always tell people to look at http://www.echoecho.com/school.htm Eric
Davy Kelly
Ranch Hand
Joined: Jan 12, 2004
Posts: 384
posted
0
guys thanks, But I have taken on some of the suggestions, but nothing is displaying, have I got any of the code wrong. I have now placed the script in the body, but to no joy. Davy
Pauline McNamara
Sheriff
Joined: Jan 19, 2001
Posts: 4011
posted
0
Hi Davy, When I have a whole bunch of stuff that I want to happen and none of it is , I usually back up and simplify to a point where *something* is going right. Then from there I build on more functionality. I took your code and went backwards, stripped it down to its first step. It still didn't work. So, one at a time, I changed some things that looked a little funny. Here's what I got to work:
What I changed: I replaced the quotes with straight ones, don't know what that's about. And I changed "Javascript 1.2" to "Javascript1.2". Took out the comments within the script tags. Maybe that's a starting point for you...
I copied your example and your quote characters turned into those weird 'smart quote' things that Word uses. Did you copy this out of a Word document or any such? In any case, they need to be replaced with 'real' quote characters. So here's my reformatted version (updated a bit to a more modern style):
which produces the following in IE6:
0 1 2 3 4 5 6 7 8 9 10 100Your name is Bear
Davy Kelly
Ranch Hand
Joined: Jan 12, 2004
Posts: 384
posted
0
Hello everyone, Thanks very much, who would have guessed it was all due to those stupid microsoft dudes who worked on word....? Because of the distance learning course, I tend to copy things and take notes onto word. so when i copied the whole program of javascript, i copied it exactly. so you can see I was getting a little annoyed it did not work. So i changed all of those double quotes that were curly, and put in the notepad ones, and it worked. Thanks again, no doubt you will see me again picking your brains about javascript. p.s. here is my code changed.
thanks Davy
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
6
posted
0
I would recommend EditPlus2 for coding JavaScript or HTML. It is a Notepad like tool with added features....
Davy Kelly
Ranch Hand
Joined: Jan 12, 2004
Posts: 384
posted
0
is it like textpad, is it free? Davy
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
6
posted
0
It is like TextPad, it is free but if you do not want to have a pop up appear everytime you load it, then you have to pay. I click the OK button all the time and do not get annoied by it, others do. It supports a bunch of languages besides JavaScript and HTML. Al I can say is I perfer it over using Notepad since I am a color coded phreak with my syntax which you can change to whatever you want it to be.... Download it and try it..... Edit Plus Homepage Eric
Davy Kelly
Ranch Hand
Joined: Jan 12, 2004
Posts: 384
posted
0
I tried textpad but did not like it, cause i had to make my own colours for the coding i did. i have downloaded the editplus 2 program, I have just copied a java program i did a few months ago, and I do like the colours it produces. so I think this will be easier to use. I can bear the clicking, but after 30 do you have to buy it, or can you just keep clicking away at the pop up??? Davy
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
6
posted
0
I am on like day 200+ You can even customize your own colors if you want it to vary a little. You can chang the preferences for any language...Java, JavaScript, ASP, etc. I think it is Document, Permanent Settings and it would be under file with settings... To lazy to look.... Eric
Davy Kelly
Ranch Hand
Joined: Jan 12, 2004
Posts: 384
posted
0
Thanks Eric, some good info there. thanks everyone too for helping me out with my small problem. I will call on you soon. Davy