JavaScript in HTML 5
Client side scripting
Introduction
There are
variety of scripting languages used to develop dynamic web pages.
JavaScript
was initially created to ‘make web pages alive’.
They don’t
need a special preparation or a compilation to run .
Using HTML
one can only design a web page but cannot implement any logic on web browser
like addition of two numbers ,check any condition ,looping statement ,decision
making statements ,etc.
This is
possible by embedding JavaScript block into HTML.
Scripting
language
A script is
a list of commands that are executed by a scripting engine.
Script are
used to generate dynamic web pages on web .script can be opened and edited by using a text editor .like
notepad..etc
Insertion of JavaScript in HTML:
JavaScript
can be use for client side or server side scripting languages .
JavaScript
code can be inserted in HTML program between
<script> and </script>
Tag.
Language
attribute is used to set scripting language .you can place any number of
scripts in HTML.
There are
two methods to insert JavaScript in HTML .
Script can
be placed in<body>or in <head> section of an HTML or in both.
|
<!doctype html> <html> <head><title>first</title></head> <body> <script language=”javascript”> //javascript statement </script> </body> </html> |
Script in <body>tag.
|
<doctype html> <html> <head><title>second</title> <script
language=”javascript”> //javascript statement </script></head> <body> </body> </html> |
Script
in <head>tag.
Variables
The
variables is a basic unite of storage in a JavaScript program.
Rules to declare variables:
Variable
name may consist of alphabets ,digits and underscore and dollar character with the following rules:
1.They must
start with alphabet .
2.Uppercase
and Lowercase are distinct .This means that variable ’sum’ is not same as
“SUM”.
3.It should
not contain blank space or special
symbols except underscore.
4.Standard
Keywords are not allowed as variable name .for eg- document,while.
5.Variable
name can be limited up to 255 characters.
Variable
name in javascript is declared with keyword ‘var’.
Syntex:
Var
variablename;
Var
variablename,variablename;
//to
declare more then one variable ,variablename are separated by a comma.
Example:
Var a//variable
a,b and c have been declared.
Var z=40,y=100//declaring
variables with initialization.
Comments