Java Scripting Part2-Information Technology-Lecture Handout, Exercises of Information Technology

Main tpoics for the course are mentioned here. What is E-Commerce and its type. Networking Devices. Markup languages. Security issues. Data mining. E-business. Cryptography and public key infrastructure. Electronic Data Exchange. Internet marketing. ERP. This lecture includes: Java, Scripting, Addition, Subtraction, Document, Object, Modification, Html, Script, Language, Function

Typology: Exercises

2011/2012

Uploaded on 08/11/2012

duraid
duraid 🇮🇳

4.3

(3)

72 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
E
E-
-C
CO
OM
MM
ME
ER
RC
CE
E
I
IT
T4
43
30
0
V
VU
U
© Copyright Virtual University of Pakistan 61
Lesson 14
JAVA SCRIPTING (CONTINUED….)
We can also get the result of addition or subtraction written on a page using ‘write’ function
of the document object. Again we need to do a slight modification in the code as shown
below.
<HTML>
<script language="JavaScript">
<!--
function Addit()
{
var num1=document.Calform.One.value;
var num2=document.Calform.Two.value;
document.write("The result of this addition is " +
(parseFloat(num1)+parseFloat(num2))); }
function minus()
{ var num1=document.Calform.One.value; var num2=document.Calform.Two.value; document.write("The
result of this subtraction is " + (parseFloat(num1)
parseFloat(num2)));
}
//-->
</script>
<BODY>
<FORM name="Calform">
<P>
First Number:<INPUT TYPE="TEXT" NAME="One" maxlength="3">
<P>
Second Number:<INPUT TYPE="TEXT" NAME="Two" maxlength="3">
<P>
<INPUT TYPE="button" NAME="Add" VALUE="Add Them!!" onclick="Addit()">
<INPUT TYPE="button" NAME="Minus" VALUE="Subtract Them!!"
onclick="minus()">
<INPUT TYPE="RESET" VALUE="Reset!">
</FORM> </BODY>
</HTML>
When a user types 3 and 9 in the two text boxes, respectively, as shown in Fig. 1 below and
presses ‘AddThem!!’ the addition of two nos. ‘12’ is written on a web page (Fig. 2). On
clicking ‘Subtract Them!!’ the subtraction of two nos. ‘-6’ is written on a page (Fig. 3). Note
that in the brackets of ‘document.write’ we concatenate or join some text information called
string (within double quotation marks) with the addition/subtraction of two nos. using ‘+’ sign. The
addition/subtraction of nos. is achieved using function ‘parseFloat()’, that is, a function of predefined global
object.
docsity.com
pf3
pf4
pf5
pf8

Partial preview of the text

Download Java Scripting Part2-Information Technology-Lecture Handout and more Exercises Information Technology in PDF only on Docsity!

Lesson 14 JAVA SCRIPTING (CONTINUED….)

We can also get the result of addition or subtraction written on a page using ‘write’ function of the document object. Again we need to do a slight modification in the code as shown below.

First Number:

Second Number:

When a user types 3 and 9 in the two text boxes, respectively, as shown in Fig. 1 below and presses ‘AddThem!!’ the addition of two nos. ‘12’ is written on a web page (Fig. 2). On clicking ‘Subtract Them!!’ the subtraction of two nos. ‘-6’ is written on a page (Fig. 3). Note that in the brackets of ‘document.write’ we concatenate or join some text information called string (within double quotation marks) with the addition/subtraction of two nos. using ‘+’ sign. The addition/subtraction of nos. is achieved using function ‘parseFloat()’, that is, a function of predefined global object.

docsity.com

Fig. 1

Fig. 2

Fig. 3 Multiply and divide calculator

See the following code:

Multiply and Divide Calculator

First Number:

Second Number:

docsity.com

A Drop-Down List of Links

Result is shown in Fig. 6 below.

Fig. 6

In the above example, event handler ‘onchange’ has been used, having the effect that when an option is selected by the user the control is shifted to the above defined function GoToIt(list). Due to the key word ‘this’ information/list contained in the select tag is available to the argument ‘list’ of the function GoToIt(). When the function would be executed the value of the selected option would be assigned to the variable ‘selection’. Due to location.href=selection, the existing location of the web page is changed to the location of the option/web page that has been selected and that particular web page opens. ‘Location’ is another predefined browser object.

docsity.com

Example - If Statement IF statement in programming is used to alter the course of execution of code depending upon the value of a condition. See the following example:

First Number:

Second Number:

Results are shown in Figures 7 and 8 below.

Fig. 7

docsity.com

Note that using for loop we are able to generate six different levels of headings in HTML.

Some predefined JavaScript objects

A list of some commonly used predefined JavaScript object is given below: Global Array String Math Date Global object is an object with globally-accessible variables/properties and functions. Netscape navigator and internet explorer implement Global object, but do not allow it to be explicitly created or referenced. Instead its properties and methods are referenced directly. NaN - ‘not a number’ is one of its properties. ‘parseFloat(string)’ that parses the string as a floating point number, is the example of a function/method of Global Object. Note a general difference between properties and functions of an object in that the names of the properties are not followed by small brackets whereas the names of the functions do have small brackets following their names. Information contained in the small brackets of a function is called arguments. Also note that generally properties and functions of an object are invoked/referenced by typing the name of the object followed by a dot before typing the property or function name, e.g, document.write().

Array Object also has different properties and functions. ‘Length’ is an important property of this object that identifies the length of the array. Its methods/functions include toString(), reverse(), sort() etc. Array Example

Using Arrays

Using Arrays

Result is shown in Fig. 10 below.

Fig. 10 docsity.com

Math object provides a standard library of mathematical constants and functions. Following example shows some properties and methods of this object.

Using the Math object

Using the Math object

Result is shown in Fig. 11 below.

Fig. 11

docsity.com