To get started with JavaScript, you will want to be able to see the tag that will set a script apart from the HTML. The tags used to begin and end a script are the <SCRIPT> and </SCRIPT> tags. The opening tag should appear like this:
| <SCRIPT language="JavaScript"> |
The language="JavaScript" command is there so the browser can tell the code that follows is in JavaScript and not another scripting language, such as VBScript. The javascript code will follow this tag, and end with the </SCRIPT> tag:
| <SCRIPT language="JavaScript"> ........JavaScript Code........... </SCRIPT> |
You can have as many <SCRIPT> tags as you need throughout the body of your HTML document, just as though it were a normal tag. Just remember to close each tag before you go on! Also, if you are going to use JavaScript functions (we will get to these later on) , you will need to place your functions inside the <HEAD> </HEAD> tags of your document. This way, your functions are loaded before the page begins to display, and you won't see all kinds of JavaScript errors. Here is an example:
| <HEAD> <TITLE>My World</TITLE> <SCRIPT language="JavaScript"> function cool() { JavaScript Stuff... } </SCRIPT> </HEAD> |
Now, there is still one last thing you should see before we begin writing scripts. Since there are older browsers being used out there, they do not recognize the <SCRIPT> tag. Rather than performing your javascript, they will display the text of your script as though you meant for it to be a few lines of text on the screen. To get around this problem, you have to trick the browser into ignoring the text within the <SCRIPT> tag. This is done by using an HTML comment. The older browsers will ignore the text inside the comments, but a JavaScript capable browser will go ahead and perform your script. Here is how to do it:
| <SCRIPT language="JavaScript"> <!-- This opens the HTML comments that will hide the script from old browsers ......Javascript Statements....... //--> This closes the comment section and the browser will read on normally </SCRIPT> |
Pretty neat, isn't it? Of course, it's not as neat as getting to an actual script, so let's get going! On we go, to the section: The MouseOver- Your First Script.
Related Articles
- Statusbar MessageThis is a quick, and quite simple tutorial. Now its not html, it uses Javascript. What it does is lets you customize what it says in the status bar usually at the bottom left of your browser. Right now in your browser it should say Infinite Designs.org ..... Heres how to make it do that...
- Form ValidationLearn the different ways of validating your form with Javascript.
- PHP/MySQL Tutorial SystemThis Tutorial will run you through the basics of building your own Tutorial CMS!
- Javascript Table RolloversHow you can get a table effect on rollover.
- JavaScript Password ProtectionOK, I finally got around to writing the javascript password protection tutorial. You will see the example script here is pretty straightforward, but it is also pretty easy to get around. Ill tell you why and give you links to more secure scripts later in this tutorial.
- Last Modified, Loading Time, Preload your ImagesLast Modified, Preload your Images, Loading Time. In this tutorial you will find scripts for this topics.
- Using Flash And Java To Create Pop-UpsWith Flash it is quite common to have a customized pop up window to hold your flash movie. This is almost always done using HTML and JavaScript. Well, what about having buttons in your flash movies that will open customized pop up windows? In this tutorial I am going to show you how to incorpora...
- 4 Powerful Features of Javascript Programming LanguageIn the community of web developers and surfers, Javascript is highly popular as client side scripting language for web browsers. Lets take a look at some of the features of this language.
- Client Side ScriptingHowever, this is not to say that other technologies are not extremely useful. Several technologies have proven to be just as important as CGI for the average Internet developer. These technologies focus on putting the demands of computation in the hands of the client instead of the server...
- Professional Web Host LayoutThis is no doubt my longest tutorial yet, so I suggest you save this every few minutes incase you loose it. (ie. computer freeze, which everyone hates)
