Scripting Language A scripting language or script language is a programming language that supports...

11
Introduction to J AVA S CRIPT Chapter-No: 01 JavaScript BasicsCourse Instructor: ILTAF MEHDI IIT Lecturer, MIHE, Kart-i Parwan branch, Kabul JAVA_SCRIP T

Transcript of Scripting Language A scripting language or script language is a programming language that supports...

Page 1: Scripting Language A scripting language or script language is a programming language that supports the writing of scripts. The term script is typically.

Introduction to JAVASCRIPT

Chapter-No: 01“JavaScript Basics”

Course Instructor:ILTAF MEHDI

IIT Lecturer, MIHE, Kart-i Parwan branch, Kabul

JAVA_SCRIPT

Page 2: Scripting Language A scripting language or script language is a programming language that supports the writing of scripts. The term script is typically.

2

Scripting Language• A scripting language or script language is

a programming language that supports the writing of scripts.

• The term script is typically reserved for small programs (up to a few thousand lines of code).

• Scripting languages, which can be embedded within HTML, commonly are used to add functionality to a Web page, such as different menu styles or graphic displays or to serve dynamic advertisements.

• These types of languages are client-side scripting languages, affecting the data that the end user sees in a browser window.

Page 3: Scripting Language A scripting language or script language is a programming language that supports the writing of scripts. The term script is typically.

3

JavaScript• JavaScript is a scripting language that enables

web developers/designers to build more functional and interactive websites.

• Common uses of JavaScript include:I. Alert messagesII. Popup windowsIII. Dynamic dropdown menusIV. Form validationV. Displaying date/time

Page 4: Scripting Language A scripting language or script language is a programming language that supports the writing of scripts. The term script is typically.

4

THE FIRST SCRIPT• Knowing that JavaScript needs to be entered

between <script> tags, is a start. • But there are a few other things you need to know

before writing your first JavaScript:1. JavaScript lines end with a semicolon.2. Always put the text within " ".3. Capital letters are different from lowercase letters.Note:-Incorrect capitalization is probably the mostcommon source of error for JavaScript programmers

on all levels!!

Page 5: Scripting Language A scripting language or script language is a programming language that supports the writing of scripts. The term script is typically.

5

THE FIRST SCRIPT

<script type="text/javascript">

document. write("JavaScript is not Java");

</script>

Page 6: Scripting Language A scripting language or script language is a programming language that supports the writing of scripts. The term script is typically.

6

Document object• The document object is one of the most

important objects of JavaScript. • Shown below is a very simple JavaScript code:document.write("Hi there.")• In this code, document is the object. write is

the method of this object. ----------------------------------------------------------------• Let's have a look at some of the other

methods that the document object possesses.

Page 7: Scripting Language A scripting language or script language is a programming language that supports the writing of scripts. The term script is typically.

7

lastModified• You can always include the last update date on

your page by using the following code: <script language="JavaScript">document.write("This page created by Iltaf Mehdi.

Last update:" + document.lastModified);</script> • All you need to do here is use the lastModified

property of the document. • Notice that we used + to put together This page

created by John N. Last update: and document.lastModified.

Page 8: Scripting Language A scripting language or script language is a programming language that supports the writing of scripts. The term script is typically.

8

bgColor and fgColor

• Lets try playing around with bgColor and fgColor:

<script language=“javascript”> document.bgColor="black“; document.fgColor="#336699“;</script>

Page 9: Scripting Language A scripting language or script language is a programming language that supports the writing of scripts. The term script is typically.

9

WHERE TO PLACE IT• Since JavaScript isn't HTML, you will need to let

the browser know in advance when you enter JavaScript to an HTML page. This is done using the <script> tag.

• You can place your scripts in any of the following locations:

1. Between the HTML document's head tags.2. Within the HTML document's body (i.e. between

the body tags).3. In an external file (and link to it from your HTML

document).

Page 10: Scripting Language A scripting language or script language is a programming language that supports the writing of scripts. The term script is typically.

10

External JavaScript File

• You can place all your scripts into an external

file (with a .js extension), then link to that file

from within your HTML document.

• This is handy if you need to use the same

scripts across multiple HTML pages, or a

whole website.

Page 11: Scripting Language A scripting language or script language is a programming language that supports the writing of scripts. The term script is typically.

11

External JavaScript File

• To link to an external JavaScript file, you add a src

attribute to your HTML script tag and specify the

location of the external JavaScript file.

<script

type="text/javascript“

src="external_javascript.js">

</script>