Learn Javascript

Let us start to share our javascript knowledge…

A javascript should be
<script language=‘javascript’>
</script>

Example Javascript:
<script language=‘javascript’>
alert(‘hi’);
</script>

Sorry but no.

[list][]The language attribute is long-since deprecated. It’s original intention was to prevent older web browsers from running scripts that they wouldn’t understand, which didn’t work as well as was intended.
[
]The type attribute is the accepted way to specify the type of script, although as javascript is the defacto default, even that can be left out
[]Double quotes are accepted standard for quoting html attributes
[
]Inline scripting is to be avoided as much as possible, so the script should be loaded from an external file instead.
[/list]

That results in:


<script type="text/javascript" src="js/script.js"></script>

which could even be reduced down to:


<script src="js/script.js"></script>

The script would remain as:

js/script.js


alert('hi');

If you really want to make sure that the code only runs as JavaScript then you’d use:

<script type="application/javascript" src="js/script.js"></script>

text/javascript is deprecated but is commonly used because to use the correct application/jaascript means that IE will not attempt to run the code as JScript and since IE doesn’t actually support JavaScript (only JScript and vbScript) it is unable to run the script if you use the “correct” JavaScript MIME type.
The only time you’d use the language attribute on a script tag is for server side languages. For example the long form of the PHP script tag is:

<script language="php">
// PHP code goes here
</script>

The shorter <?php ?> version is more commonly used though.