Home arrow JavaScript arrow Introduction to JavaScript
Introduction to JavaScript PDF
Friday, 23 November 2012
work in progress...

JavaScript is an object oriented scripting language that is supported by modern browsers very usefull at enhancing user interface within your browser. Also it is used to create dynamic web sites.

Example 1. Run  JavaScript code from a html file

Let's see a first example which will display a string in your browser:

example1.html
<html>
<head><title>Example 1</title></head>

<body>
  <p>
    <script type="text/javascript">
     
      document.write("This is a string.");
     
    </script>
  </p>
</body>
</html>


Example 2. Run JavaScript from an external file

This is most common use/placement of a JavaScript. We will have two files, example2.html which will be our web page and a separate file (myscript.js for this example) which will be our JavaScript script:

example2.html
<html>
<head>
  <title>Example 2. Runing a JS script from outside file</title>
  <script type="text/javascript" src="myscript.js"></script>
</head>

<body> 
  <p id="displayString"></p>
</body>
</html>


And the script file is:

myscript.js
window.onload = echoString;
 
 function echoString() {
  document.getElementById("displayString").innerHTML = "This is\
    just another string"
;
 }




Last Updated ( Saturday, 24 November 2012 )
 
< Prev

Other BSD Systems

OpenBSD

Misc

Solaris

Polls

Best BSD firewall?