Java Script
What is Java Script?
• It is a Light weight programming language.
• Java script can be inserted into an HTML
page.
• Java Script is an open Scripting language
that any one can use it without purchasing
the license.
• Java script is supported by major browsers
like Netscape ,Internet Explore.
How does it works?
• When a Java Script is inserted into an
HTML document, the internet browser will
read the HTML and interpret the Java
Script.
• The Java Script can be executed
immediately or when some event occurs.
What a Java Script can do?
• Java Script gives HTML designers a programming
tool.
• It can enhance the dynamic and interactive feature
of your page by allowing you to perform
calculation.
• Java Script can
> check forms
> write interactive games
> add special effects
> Customize graphics selection
• Java Script can put a dynamic text into an
HTML page.
Ex:
document.write(“<h1>”+name +”</h1>” );
can write a variable text into the display of
HTML page just like a static HTML text:
<h1>Hello</h1> does.
• Java Script can read and write HTML elements.
• Java Script can react to events. A Java Script can
be set to execute when something happens like
when a page has finished loading or when a user
clicks on an HTML elements.
• Java Script can be used to validate data in a form
before it is submitted to a server.
<script> Tag
• The primary method of including Java Script
within HTML is by using the <script> tag. To
specify scripting language name, we have to use
“language attribute” with <script> tag.
Ex.
<script language=“Java Script”>indicates java script
<script language=“VBS”>indicates VB Script
Sample Code:
<html>
<head>
<title> Java Script Test Program </title>
</head>
<body>
<script language=“JavaScript”>
document.write(“Hello”);
</script>
</body>
</html>
Sample 2:
<html>
<head>
<title> Java Script Test Program </title>
</head>
<body>
<script language=“JavaScript”>
<b>
document.write(“Hello”);
</b>
</script>
</body>
</html>
Sample 3:
<html>
<head>
<title> Java Script Test Program </title>
</head>
<body>
First Time:
<script language=“JavaScript”>
alert(“1st Time”);
</script>
Second Time:
<script language=“JavaScript”>
alert(“2nd Time”);
</script>
Third Time:
<script language=“JavaScript”>
alert(“3rd Time”);
</script>
</body>
</html>