It is compatible with all major web browsers, and is relatively easy to learn. This makes it one of(if not) the most popular scripting language on the internet.
Just like a HTML document, when requested by the web browser the document is located and sent by the web server. It is then up to the web browser to execute the code
- Validating form data.
- Confirmation or notification
- Dynamically changing content
- Adding tool-tips to your site
To insert a script into our HTML we use the opening <script> tag and the closing </script> tag.
As you can see from the above code we need to declare a type when using the script tag. We do this by typing type="text/javscript". Just as we would if we were embedding CSS code into a html document.
You can have as many script tags in your HTML page as required. There is no limit to the amount of scripts you can have on one single page.
Some older browsers may have problems reading or executing Javscript code. If a viewer is using one of these browsers the code will be displayed as content on your page, rather than being executed.
To get around this we use the HTML comment tag, this hides the script from the browser. Take a look below for an example of this:
If you have used HTML comments before you will probably have noticed that our end tag //--> is slightly different from the normal comment closing tab -->.
Things to remember
- Text should always be surrounded by double quotation marks.