Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :
03/24/2008
Times viewed :
2511
How to use JavaScript?
Introduction
JavaScript can be used either directly in the HTML page or
in a separate file. The file should then get the .js extension. If you are
using it in a HTML then you will need to include the <script> tag and if
you are using a separate file, then you don’t need this tag. Usually the
<script> tag is used in the <head> tag but you can insert it
wherever you want. However it is recommend leaving it in the <head> tag.
That way your code will be differentiated from the HTML code and furthermore
your HTML page will be easier to read and understand. The <script> tag
takes an attribute called “type”. This attribute can be used to define the
scripting language – in our case it will be “JavaScript”. You can also use the
“language” attribute to define the scripting language. However this attribute
is deprecated and it is recommend using the type attribute. You can include any
amount of <script> tags.
Example (from HTML)
<html>
<head>
<script type="text/javascript">
document.write("This
is from inline HTML code.")
</script>
</head>
<body></body>
</html>
Output
Example (From a separate file)
<html>
<head>
<script type="text/javascript">
document.write("This
is from inline HTML code.<br>")