Open Directory Site JavaScript Tutorials

ASP | XML | VBScript | JavaScript | ADO | CSS | XMLDOM | PHP | Operating Systems

Home >> JavaScript >> Introduction to JavaScript

Introduction to JavaScript

 

What is JavaScript?

· JavaScript is a scripting language

· A scripting language is a lightweight programming language

· A JavaScript is lines of executable computer code

· A JavaScript can be inserted into a HTML page

How does it work?

When a JavaScript is inserted into a HTML document, the Internet browser will read the HTML and interpret the JavaScript. The JavaScript can be executed immediately, or at a later event.

What can a JavaScript do?

JavaScript gives HTML designers a programming tool

HTML authors are normally not programmers, but since JavaScript is a very light programming language with a very simple syntax, almost anyone can start putting small "snippets" of code into their HTML documents.

JavaScript can put dynamic text into a HTML page

A JavaScript like this: document.write("<h1>" + name + "</h1>") can write variable text into the display of a HTML page, just like the static HTML text: <h1>Bill Gates</h1> does.

JavaScript can react to events

A JavaScript can be set to execute when something happens, like when a page has finished loading or when a user clicks on an HTML element.

JavaScript can read and write HTML elements

A JavaScript can read an HTML element and change the content of an HTML element.

JavaScript can be used to validate data

JavaScripts can be used to validate data in a form before it is submitted to a server. This function is particularly well suited to save the server from extra processing.

 

How to put a JavaScript into an HTML document

<html>

<head>

</head>

<body>

<script language="JavaScript">

document.write("Hello World!")

</script>

</body>

</html>

And it produces this output:

Hello World!

To insert a script in an HTML document, use the <script> tag. Use the language attribute to define the scripting language.

<script language="JavaScript">

Then comes the JavaScript: In JavaScript the command for writing some text on a page is document.write:

document.write("Hello World!")

The script ends:

</script>

Examples

1.How to write text on a page

Coding

<html>

<body>

<script language="JavaScript">

document.write("Hello World!")

</script>

</body>

</html>

Output

Hello World!

2.How to format the text on your page with HTML tags

Coding

<html>

<body>

<script language="JavaScript">

document.write("<h1>Hello World!</h1>")

</script>

</body>

</html>

Output

Hello World!

Cheap Web Hosting Articles - Web Site Design & Web Hosting Tutorials - Domain Hosting