home > javascript > the code

javascript code

you can program javascript code in roughly three ways.

direct:

execute the code immediately at the moment the browser gets the page from the internet

<script language="javascript">  
...some code...  
</script>  
   
inline:

execute the code after an event has occured

<a href="somepage.htm" onmouseover="...some code...">

   
external:

your code resides in another file on the website (eg. somecode.js), so that other html-pages can also use it. write once, use often.

<script language="javascript" src="somecode.js">

a file called "somecode.js" consists:
...some code...

of course, in this example you have to have a separate file called "somecode.js". there is no real need to put .js at the end of the file. it's just for convienience and it is also good practice. do it anyway, you will be glad you did.

   
tips:

when writing javascript code, you work in the "code view" in dreamweaver. the good thing about dreamweaver is that it takes care of the color coding of your scripts. just like the way lingo does in director.

try to work very tidy. else you will have difficulty reading the code afterwards. put one statement on each line. smart indent every line of code.

document your code, by adding comments. after a few weeks you usually don't have a clear clue as to what the script does. comments help you get going very quickly.

when you get lost, don't panic. also, internet explorer does not give very good feedback when you make programming mistakes (syntax errors and the like). look at the page in another browser.

the best way to learn is from somebody elses code. look at other programmer's code. check the source of webpages with javascript and try to read the code. this is also a good way to get yourself familiar with javascript. you don't have to immediately understand exactly what's going on.

learn to use the netscape javascript reference: browse through the index. it has all you need.