Home | Add to Favorites | Ebooks Directory | News  
Javascript   Resources
Home
Javascript  Article
JavaScript Tutorial 
Java Script Example
Books
JavaScript  Download
Java script Reference
JavaScript Tutorial
Javascript Tutorial Continued

Example 1
The script below prints "hello world" in the browser. A simple "Hello World" script The language attribute of the <script> tag should be "javascript"
The document object's write property writes the string argument into the browser. HTML can be embedded with javascript

 

<html>
<body>
<script language="javascript">
document.write("hello world");
</script>
</body>
</html>

The javascript code has to be enclosed within the script tags with language attribute. script can be specified anywhere in the html code .It can be embedded within the
<head></head> tags also


Example 2

The script displays a message box with OK button containing "hello world" message. This message box is typically called "Alert Box".The Alert Box has a single OK button, on clicking
which the alert box gets closed. The semicolon after each statement is optional.

<html>
<body>
<script language="javascript">
alert("hello world");
</script>
</body>
</html>

 

Example 3

Javascript can perform arithmetical operations also like any other programming language. HTML code cam be embedded within script. The script below finds the factorial of numbers one to nine. The for loop syntax is simple and similar to that used in Java or C programming languages.

<html>
<body>
<script language="javascript">
document.write("<h2>Table of Factorials</h2>");
for(i=0;f=1,i<10;i++,f *= i)
{
document.write(i+" ! = "+f);
document.write("<br>");
}
</script>
</body>
</html>

 

                                                            Go To Index