CSS HTML About Contact

Java Script

JavaScript is THE scripting language of the Web. JavaScript is used in billions of Web pages to add functionality, validate forms, communicate with the server, and much more. JavaScript is easy to learn. You will enjoy it.

What is JavaScript?


Are Java and JavaScript the same?


NO! Java and JavaScript are two completely different languages in both concept and design! Java (developed by Sun Microsystems) is a powerful and much more complex programming language - in the same category as C and C++.

Adding JavaScript to your HTML


The example below writes a

element with current date information to the HTML document:

<html> <body> <h1>My First Web Page</h1> <script type="text/javascript"> document.write("<p>" + Date() + "</p>"); </script>

Example Explained


To insert a JavaScript into an HTML page, use the tells where the JavaScript starts and ends

<html> <body> <h1>My First Web Page</h1> <p id="demo">This is a paragraph.</p> <script type="text/javascript"> ... some JavaScript code ... </script> </body> </html>

The lines between the contain the JavaScript and are executed by the browser. In this case the browser will replace the content of the HTML element with id="demo", with the current date

<html> <body> <h1>My First Web Page</h1> <p id="demo">This is a paragraph.</p> <script type="text/javascript"> document.getElementById("demo").innerHTML=Date(); </script> </body> </html>

Without the

<script>

tag(s), the browser will treat "document.getElementById("demo").innerHTML=Date();" as pure text and just write it to the page:

Some Browsers do not Support JavaScript


Without the script tag(s), the browser will treat "document.getElementById("demo").innerHTML=Date();" as pure text and just write it to the page:

<html> <body> <script type="text/javascript"> <!-- document.getElementById("demo").innerHTML=Date(); //--> </script> </body> </html>