Scripting Language





The actual strength of web page is hidden in scripting language like as JavaScript, VBScript etc. The scripting language is like as best quality perfumes you sprayed over your body when you go any auspicious occasions or party organized by your boss or business organizations where your personality bloom up with sweet aroma of perfume. The scripting language is a vitamin for web-document to keep it healthy and attractive.

The history of scripting language is stared with Apple’s HyperTalk (1987). It is designed to produce script to run in HyperCard. The Macromedia Lingo, a full-featured object oriented, is also scripting language for Director. Macromedia Director is first popular software used for interface designing and animations. The capability of Director is directed through Lingo Script. MetaTalk, ToolBooks are also scripting language. This language is not easy as other programming language. The web browser supports some scripting languages in which (a) JavaScript, and (b) VBScript are most popular. The web document’s visual graphics interface is designed through these languages.

JavaScript is an object based scripting language for Internet developed by Netscape for Netscape Navigator 2.0 and its first name was LiveScript which is changed into JavaScript after licensing agreement with Sun MicroSystem. It is used to change control of web documents with Java fragrance in easy steps. The Jscript is the JavaScript version of Microsoft. It is easy, light weighted, visual graphics coding machine. This script is not compiled, but only interpreted by browser. Some knowledge of web architecture and HTML is essential to understand and learn scripting languages.

Some features:

  • It is a platform independent scripting language.
  • It is supported by Microsoft Internet Explorer 3 (and above) and Netscape Navigator 2.01 or later version.
  • It is a case sensitive language so a misplaced capital can undermine the operations.

 

JavaScript has three important elements:

 

(a) Objects: JavaScript is an object based scripting language, so all the activities revolve around objects. We interact with objects, and its properties (attributes). There are many objects in the world of scripting languages like as documents, frame, form, button, etc.

 

(b) Methods: Methods are techniques that are used to perform some actions for objects. Each object has at least one method.

Example:

(i) Click(): Method of object button

(ii) Submit() : Method of object form

(iii) alert(), prompt(), open(), close(): method of Frames

(iv)Open(), Close(), Clear(): Method of documents

(v) SetTimeout() and ClearTimeout() are window method user to set and clear timer respectively.

 

(c) Event: Events controls sequences of activities within a scripted program. The Onload() and Upload() are example of window events.

Generally, scripting languages are allowed in HEAD section of HTML documents. We write Javascript within <SCRIPT LANGUAGE=”JavaScript”> and </STRIPT> tags. The following examples change document background color and display text.

 

WEB DOCUMENT

<html>

<head>

<script>

Document.writeln(“<center><h1>Hello ! world</h1></center>”);

Document.bgcolor=”RED”;

Document.writeln(“<CENTER><h1>MY First JavaScript</h1></CENTER>

</SCRIPT>

</head>

<body text=”yellow”>

<hr>

</body>

</html>

 

Document and windows objects

 

The window is a parent object and document is a child document of windows. Each object has properties and methods.

Properties and Methods

Comment

Alert(message)

It is an interface element used to display alert windows with OK button.

Confirm (message)

It is also window object and it display confirmation dialog box with OK and cancel button.

Grammar:

Confirm(message)

document.anchor

document.bgcolor

It is used to change background color.

Example:

Document.bgcolor=”red”

document.close

document.fgcolor

It is used to change foreground color.

Example:

document.bgColor=”red”

document.open()

document.write(string)

Used to write documents.

Example:

document.write(“ABC Animation and Graphics”)

document.writeln(string)

Used to write document, followed by a hard return.

Prompt(message)

It is also window object like as alert. It displays input box with OK and cancel button.

Grammar:

Prompt(message, [Default])

Window.close()

It is used to close open window.

Window.document

The current document is displayed by window.

Window.location

It is used to access URL of the current document.

Window.open()

It is used to open new browser window and display document referenced by URL or name.

 

String Object

 

String is also object and it has some methods.

String Object

Comments

Anchor(name)

It is used for anchoring the text.

Big()

It is a string object and it works like as <BIG> and </BIG tags.

Example:

String.big()

Blink()

It is string object behave like as <BLINK> and </BLINK> tags.

Grammar:

String.blink()

Bold()

It is also string that behaves like <B> and </B> tag.

Grammar:

String.bold()

Fontcolor(color)

It is used to change font color.

Grammar:

String.bold(“green”)

fontSize(number or %)

It is used to determine size of fonts.

Example:

String.fontsize(“15”)

Italics()

It is used to determine size of fonts.

Grammar:

String.italizes()

Small()

It is a javascript version of <small. And </small> tags.

Grammar:

String.small()

Strike()

It is a javascript version of <S> and </S> tags.

Sub

It is used for subscript.

Grammar:

String.sub()

Sup

It is used for superscript.

Grammae:

String.sub()

tolowerCase()

It is used to convert uppercase letter into lower case.

Grammar:

String.tolowercase()

Touppercase()

It is used to convert lower case letter into uppercase.

Grammar:

String.touppercase()

 

WEB DOCUMENT

 

<HTML>

<HEAD>

<SCRIPT LANGUAGE=”javascript”>

Str1=”HELLO ! WORLD”

Str2=” ABC DESIGN MART”

Document.writeln(str1.bold())

Document.writeln(“<BR>”)

Document.writeln(str1.italics())

Document.writeln(“<BR>”)

Document.writeln(str1.big())

Document.writeln(“<BR>”)

Document.writeln(str1.small())

Document.writeln(“<BR>”)

Document.writeln(str1.strike())

Document.writeln(“<BR>”>

Document.writeln(str1.fontcolor(“blue”))

Document.writeln(“<BR>”)

Document.writeln(str1.fontsize(“5”))

Document.writeln(“<BR>”)

Document.writeln(“WATER: H” + “2”.sub() + “o”)

Document.writeln(“<BR”>)

Document.writeln(“Mass energy relativity, E=MC” + “2”.sup())

Document.writeln(“<BR>”)

Document.writeln(str2.tolowercase())

Str3=str2

Document.writeln(“<BR>”)

Document.writeln(str3.toupperCase())

</SCRIPT)

</HEAD>

<BODY>

</BODY>

<HTML>

 

Program: This program asks to input HTML document. When we type file name and click OK buttons, the target file is accessed. The document.location.hrefd href is used to link document.

 

WEB DOCUMENT

<HTML>

<HTML>

<SCRIPT LANGUAGE=”javascript”>

fileN=prompt(“Enter HTML document name:’, “ass.html”)

document.location.href=fileN

</SCRIPT>

<BODY>

</BODY>

</HTML>

 

Example:

This sample document asks input URL. When we type URL and click OK buttons, the target URL is accessed. The document.location.href is used to link.

 

WEB DOCUMENT

<HTML>

<HEAD>

<SCRIPT LANGUAGE=”javascript”>

fileN=prompt(“Enter URL:”, Http://www.)

document.location.href=fileN

</script>

</HEAD>

<BODY>

</HTML>

 

Example:

The following codes have user-defined function named as show_me() and user interface prompt and alert are used with it. We write function attributes within curly bracket({ and }]. In FORM section Click Me  button is created, when this button is clicked, function show_me() is activated or loaded.

 

WEB DOCUMENT

<HTML>

<HEAD>

<SCRIPT>

Function show_me()

{

X=window.prompt(“Hello ! Maulik Anand”, “Hello World”);

Alert(x);

}

</SCRIPT>

</HEAD>

<BODY>

<FORM TYPE = “button” VALUE=”Click me” onclick=”Show_me()”>

</FORM>

</BODY>

</HTML>

 

Example:

In this example, user defined function show_me() has user interface alert. The function user ff as parameter.

 

WEB DOCUMENT

<HTML>

<HEAD>

<SCRIPT>

Function.show_me(ff)

{

Alert(ff.value);

Alert(ff.name);

}

</SCRIPT>

</HEAD>

<BODY>

<FORM>

<INPUT TYPE=”button” VALUE=”show” NAME=”Navneet” onclick=”show_me(this)”>

</FORM>

</BODY>

</HTML>

 

VBscript

 

The VBScript is the subset of Visual Basic and jscript is the subnet of Visual J++ (code- named Jakarta). The visual J++ is the first full blown IDE to make internet programming. The programming language is based on most popular Internet Language Java of sun Microsystem. This language is not easy as other scripting language. It has some learning curve but Visual Basic programmers have not to apply any effort for learning. So, must of the Visual Basic programmers prefer VBScript instead of JavaScript or other scripting language for Web Page Design.

The scripting language requires two things: host and script engine. The host is a program and available embedded into web browser. The web browser supports some scripting languages in which (a) JavaScript, and (b) VBScript are most popular. The web document’s visual graphics interface is designed through these languages. The script engine is usually library or set of libraries that tells the host (browser) how to interpret the script. VBScript.dll and jscript.dll are examples of script engine.

VBscript is developed by Microsoft, especially for web. It is similar to visual Basic (modern version of q-basic), and supported by internet Explorer 3 and later version. It is a procedural language in which sub-routines are used as building blocks. It is not case sensitive so prompt and Prompt have same meaning for interpreter. A script is a short program used to enhance capability and interactivity of web and placed within <SCRIPT> and </SCPIPT> tags.

Example:

<HEAD>

<SCRIPTING LANGUAGE=”VBScript”>

Document.fgcolor=”red”

Document.bgcolor=”black”

Document.write”<H1><CENTER>Hello ! World</CENTER></H1>”

</SCRIPT>

</HEAD>

 

Documents and Interface methods:

 

Objects and methods

Comments

Alert

It is used to display message. It is a user interface with sign of note of exclamation and OK button.

Bgcolor

It is used to determine background colors of documents.

Example:

Document.bgcolor=”red”

Confirm

It displays confirmation dialogue box with OK and cancel button.

Grammar:

Confirm(Message)

Document.write

It is used to display test on document.

Example:

Document.fgcolor=”Blue”

InputBox

It displays dialogue box to enter data. It has OK and Cancel burron.

Grammar:

Var=InputBox(Message, “Title”, “Default message”)

Or inputBOX(message)

MsgBox

It is a user interface with OK and cancel button.

Grammar:

Var=MsgBox(Message, 0, “title”)

Or

Msgbox(message)

Prompt

It is just like as inputbox and used to accept user data with OK and Cancel button.

Grammar:

Var= prompt(message,{default])

Example:

Ans=prompt(“What is your name?”, “navneet”)

 

WEB DOCUMENT

<HTML>

<HEAD>

<SCRIPT LANGUAGE=”VBScript”>

Msgbox(“Name: Subash Ghimire, ilam, golbasti” & VBCrLf & “Asishwarya Vidya Niketan” & VBCrLF & “Asst.teacher”)

Document.bgcolor=”red”

Document.fgcolor=”blue”

Document.write(“<H1><CENTER>Aishwarya Vidya Niketan<CENTER></H1>”)

</SCRIPT>

</HEAD>

<BODY BGCOLOR=’#FFFFFF” TEXT=”#000000”>

</BODY>

</HTML>

 

WEB DOCUMENT

<HTML>

<HEAD>

<SCRIPT LANGUAGE=”VBScript”>

Username= inputbox(“Enter your name”)

Document.write”<H1>Your name:’ & Username &” </h1>”

Document.write”<HR>”

Document.write “<CENTER> Date:” & date() & “Time:” & Time() & “ </CENTER>”

</SCRIPT>

</HEAD>

<BODY text=”red”>

</BODY>

</HTML>

 

WEB DOCUMENT

 

<HTML>

<HEAD>

<SCRIPT LANGUAGE=”VBScript”>

Ans1=”Are you Graduate?”

Ans2=confirm(ans1)

Confirm “You are graduated from T.U”

Confirm (“You are graduated from K.U.”)

</SCRIPT>

</HEAD>

<BODY BGCOLOR=”#FFFFFF” text=”#000000”>

</BODY>

</HTML>

 

Example of prompt:

 

WEB DOCUMENT

<HTML>

<HEAD>

<SCRIPT LANGUAGE=”VBScript”>

Ans1=”Where do you live?”

Ans2prompt(ans1, “Ilam”)

Document.write”<H1>I live in “ & ans2 &” <H1>”

Ans3=prompt(“Are you vegetarian?”, “yes, I am”)

Document.write” <h1>” & ans3 & “ Negeterian <H1>

</SCRIPT>

</HEAD>

<BODY BGCOLOR=”#FFFFFF” text=”#000000”>

</BODY>

</HTML>

 

Example of input box and Msg box:

WEB DOCUMENT

<HTML>

<HEAD>

<Script Langauge=”VBScript”>

Ans1=MsgBox(“you are fond of Visual Basic Script”, 0,” Message box”)

Ans2=InputBox(“Enter your name:”, “Input Box”, “Maaulik”)

Document.write” <H1> your name:” & ans2 &” </h1>”

</Script>

</HEAD>

<BODY BGCOLOR=”#FFFFFF” text=”#000000”>

</BODY>

</HTML>



Related posts:

  1. Programming Language Grammar Every language has its own grammar. Nepali, Hindi, Mathili, Newari,...
  2. Programming Language Language is a medium of communication. There are several languages...
  3. Applet Design The JAVA is an object oriented and case sensitive language...
  4. Computer Software Generally, software is classified into two major groups (a) System...
  5. Internet The Internet grew out of work done at the US...