Saturday, July 3, 2010

Some Sample Small Programmes



1. Writing text on the browser window 
<html>
<body>
<script language="JavaScript">
document.write("Hello World!")
</script>
</body>
</html>

2. Writing Formatted Text on the Browser 
<html>
<body>
<script language="Java Script">
document.write("<h1>Hello World!</h1>")
</script>
</body>
</html>

3. Using HEAD Section
<html>
<head>
<script language="JavaScript">
function message(){ 
alert("This alert box was called with the onload 
event")
}
</script>
</head>
<body onload="message()">
</body>
</html>

4. Using BODY Section 
<html>
<head>
</head>
<body>
<script language="JavaScript">
document.write("This message is written when the 
page loads")
</script>
</body>
</html>
<!--Example E Using External script -->
<html>
<head>
</head>
<body>
<script src="myscript.js">
</script>
<p>The actual script is in an external script 
file called "myscript.js".</p>
</body>
</html> 

Try yourself.
1. Load any text editor (Notepad, WordPad, Word, 
TextPlus)
2. Create the HTML file and save it, with .HTM or 
.HTML extension. and write following HTML and javascrpt.
   <html>
   <body>
   <script language="JavaScript">
   document.write("Hello to JavaScript World!")
   </script>
   </body>
   </html>
3. Open saved file in Browser (IE, Netscape) to 
view it will display Hello to JavaScript World!.

No comments: