Page 184 - Web Applications (803) Class 12
P. 184
You are free to put as many scripts into a single document as you like, using multiple script tags.
A script embedded in HTML with the <script> tag uses the following format:
<html>
<head>
<script type=”text/javascript”>
-------Type your JavaScript Code here------------
</script>
</head>
<body>
--------Type your HTML code here------------------
</body>
</html>
Scripts can be used in four locations across the HTML content and so JavaScript scripts are categorized as
inline, internal and external script:
1. Page body: When the page is loaded in the browser, the output appears as part of the HTML content.
2. Page header: The code is written in the form of a function (a collection of JavaScript statements that are
handled as a single unit) and referenced to in another script on the same page.
3. Within the HTML tag: When JavaScript is used as an event handler (explained later in the chapter), it
interacts with HTML elements.
4. As an external file: In this scenario, the JavaScript code is stored in a .js file. In the script tag, this file is
included.
3.2 JAVASCRIPT VARIABLES
A JavaScript variable (also known as an identifier) is a storage location in the memory. The keyword var can be
used to declare variables in JavaScript. When a variable is given a value, the equal to (=) symbol is used. Users
have the option of declaring variables separately and subsequently assigning values to them, or declaring and
initialising variables at the same time.
Example:
<html>
<body>
<script>
var p = 25;
var q = 35;
var prod=p*q;
document.write(“The product is “+prod);
</script>
</body>
</html>
182 Touchpad Web Applications-XII

