12e Com
12e Com
SUMMARY
Friends,
In this chapter, we will learn the use of JavaScript and CSS using KompoZer software.
We know that HTML can be used for description of the content not for the style. Here we have discussed
how the style is used with HTML.
Click on the first radio button "style applied to all Click the Create Style rule button. You will see
the elements of type". that the CSS Stylesheets dialog box remains open
From the drop down menu choose an element to but the options will change.
create the style rule. Figure 2.4 shows the hl element just below the
As we want to create a style for Heading1, we have heading "internal Stylesheet" on the left pane of
selected hl (Heading l) from the drop down menu the window.
as shown in figure 2.3. For each element we add, a style rule will appear
in this list below the heading "internal
Stylesheet".
On the right side of the window, you will see
various tabs like General, Text, Background,
Borders, Box, Lists and Aural. Each of these tabs
can be used to give a specific style to the element.
But all the tabs may not be applicable to the
selector for which the style rule is created.
Now, let us create the style rule for hl selector.
Figure 2.4 : CSS Stylesheet dialog box with Select hl in the left pane of the window. Click the
options of h1 'Text' tab as shown in figure 2.5.
Choose "Uppercase" from the Case menu and Figure 2.8 shows the background tab after
selecting the color.
"Center" from the Alignment menu.
Figure 2.5 shows the options selected. As you
change the options, you can see the default text
in the window changes automatically according
to the styles.
To set the background color, select the
Background tab. This will open the options for
the background as shown in figure 2.6.
But in our example, we require only the selected dialog box. Choose "style rule" from the drop down
options for applying style to hl. menu.
Click on the General tab. After adding the style rule for all the elements
This will show the CSS code which is generated click OK button.
as shown in figure 2.10. Example - 2 :
If you know HTML coding you can also edit the Let us now use the CSS created for hl tag in a
code. webpage.
In Format toolbar1, select the Heading1 option to
insert a heading in the page.
When you select the Heading1 option, your
cursor will automatically be placed in the center
of the webpage (as we had applied center
alignment in CSS).
Type some text like SARASWATI VIDYAMANDAL
and to this heading gives the CSS effect and
Figure 2.10 : General tab showing the CSS code shows the CSS coding.
Thus, we have created the style to be applied to
Select Heading1 from the Formatting Toolbar1.
hl tag.
Cursor will automatically placed in the centre as
We can use the same procedure to create a style for
we have selected Center alignment for CSS.
any other element in the webpage. To add other
Now type SARASWATI VIDYAMANDAL. The
elements, click on the arrow of CSS button typed content will appear in uppercase with font
in the upper left corner of the CSS Stylesheets style "Times New Roman".
Select the source tab at the bottom of the window to view the CSS stylesheet code. The figure 2.12 shows
the CSS code in the head section of the page source code.
ANSWER (1 - B) (2 - C) (3 - B) (4 - D) (5 - A) (6 - B) (7 - A) (8 - D) (9 - C) (10 - B)
(11 - A) (12 - B) (13 - C) (14 - B) (15 - A) (16 - C) (17 - D) (18 - C) (19 - B) (20 - A)
54 2. Cascading Style Sheets and Java script
21) Using .......... we can get confirmation that CSS (A) General
is used by default by KompoZer. (B) Number
(A) Edit Preferences (C) Text
(B) Tools Preferences (D) Box
(C) (A) or (B) 28) .......... section is used to give specific style to
the HTML element.
(D) None of these
(A) General
22) How to open option dialog box in KompoZer ?
(B) Text
(A) Edit Preferences (C) Background
(B) Tools Preferences (D) All of these
(C) (A) or (B) 29) .......... button is clicked to insert an image as
(D) View Preferences the background while preparing style.
23) .......... statement is wrong about the KompoZer (A) Choose file
software. (B) Select file
(A) CSS can be added with HTML (C) Browser
(D) Select image
(B) CSS can be added easily
30) .......... tab displays the Stylesheet rule that is
(C) KompoZer can only be used for CSS
given to the element.
(D) All of these (A) General (B) Box
24) Cascade button is on ...... toolbar of KompoZer. (C) Aural (D) Code
(A) Standard toolbar 31) How many buttons are there in CSS Stylesheets
(B) Composition toolbar to prepare style ?
(C) Format toolbar (A) 5 (B) 6 (C) 7 (D) 8
(D) Drawing toolbar 32) .......... view is selected to see the source code of
CSS Stylesheet.
25) While preparing a style, if a new file is opened
(A) Design (B) Source
and not saved by giving a filename then ..........
(C) Split (D) Normal
dialog box opens.
33) .......... is false for CSS Stylesheet.
(A) Option
(A) To modify the Stylesheet user can make
(B) Page title changes in CSS file.
(C) New (B) CSS has less-code compared to that in
(D) Save HTML.
26) The element which is used to define Stylesheet (C) The webpages will load faster.
rule that CSS Stylesheet dialog box is under (D) CSS structure makes the website slow and
.......... heading. inefficient.
(A) External Stylesheet 34) .......... is the disadvantage of CSS.
(A) CSS has less-code compared to that in
(B) Internal Stylesheet
HTML
(C) Right Stylesheet
(B) Compatibility varies with different browsers.
(D) General Stylesheet (C) Stylesheet features are not supported by the
27) .......... tab is not displayed on the right side of browser
CSS Stylesheet dialog box. (D) (B) and (C) both
ANSWER (21 - C) (22 - C) (23 - C) (24 - B) (25 - B) (26 - B) (27 - B) (28 - D) (29 - A) (30 - A)
(31 - C) (32 - B) (33 - D) (34 - D)
Std.-12 : Computer Darpan – ‘Kumar’ 55
Previously www was used only for the give and
2.5 JavaScript take of data but today it is used for entertainment,
knowledge, business etc. That is why webpage
HTML was originally used to control the should impressive and more interactive while
appearance of webpages. static webpage is not very interactive .
The webpages designed using HTML, were static We can input data in the form created in HTML
and could not be changed after the browser but can not process this data for processing data,
rendered them. programming language is required. Computer
However, with the growth of Internet, people program make the page more interactive. If some
demanded the websites to have greater elements are lacking in HTML, they are
interactivity and better visual design. programming elements. By using JavaScript with
But, HTML could only provide static webpages. HTML, its capacity can be increased which help
Thus, the demand of more interactivity created us to create a dynamic webpage.
the need for a new web programming language. Remember this :
Hence, Netscape developed JavaScript. JavaScript When the user enters wrong data or leaves a field
is a scripting language that allows you to add empty, an error message should be generated and
programming aspects to your webpages. the form should not be submitted.
A scripting language is a simple, lightweight The most common form of JavaScript application
programming language that does not contain the today is client side script which runs inside a web
advanced programming functionalities of browser.
languages like C and Java. It is used to validate the data entered in the
JavaScript is used in webpages to improve the HTML forms on the client side before sending it
design and validate the forms. It adds interactivity to the server.
to HTML pages and is inserted directly into the Using JavaScript, the form is generally checked for
HTML code. the following things :
Today, mostly all the web browsers like Mozilla Has the user left any required field empty ?
Firefox, Chrome, Safari and Internet Explorer Has the user entered a valid E-mail address ?
support JavaScript.
Check whether contents of two fields are
Using JavaScript a webpage no longer remains
same or not ?
static, but can include coding that allows
interactivity with the user, control the browser Has the user entered a valid date ?
and dynamically create HTML content. Has the user entered text in the numeric data
We learnt how to create forms using KompoZer. field ? Say for example; in the quantity field
instead of numeric data, user entered text.
When the user enters data in the form, he might
leave some of the-important fields empty or may Before starting to learn about how to validate a
enter the data in a wrong format inside the field. form, let us first learn how to write a JavaScript
code.
In such cases there must be some type of
validation provided. This validation will restrict JavaScript code runs from within the HTML
users from making mistakes. webpage. Thus, the JavaScript code can be put
directly inside the webpage code as a separate
As HTML language creates static webpage, there is
section. The JavaScript code is inserted into an
no change in the activates done by the user like
HTML page, using the <script>...</script> tag.
movement of the mouse, input process or submit
The lines between the <script> and </script> tag
the form etc. There is no change in the static
contains the JavaScript code.
webpage while as JavaScript is dynamic. Necessary
changes can be done in the original page. Remember, JavaScript is a case sensitive language.
There is no change in the static page while JavaScript can be placed inside the <body> or
loading or during the display. For e.g. If we want <head> section of an HTML page. But generally
to display today’s date on the webpage, it is not it is preferred that the code be placed in the
possible. <head> tag.
56 2. Cascading Style Sheets and Java script
The <script> tag tells the browser to interpret all the text between the <script> tags as a script.
Example - 3 :
Using source view of KompoZer display the statement in the browser “HELLO MY DEAREST STUDENTS”.
Save the file using File Save. Give the page title to be displayed in the title bar of the browser screen and
press OK. Suppose we give the title JavaScript Example1. Save the file with proper name.
Click on source view of KompoZer or select view HTML source. Here we have to add the coding.
You can see that inside the <script> tag we have written a single statement document.write (“HELLO MY
DEAREST STUDENTS”).
Go to Form Define Form. Click on Advanced Edit button that will open
This will open the Form Properties dialog box as Advanced Property Editor dialog box as shown in
shown in figure 2.16. figure 2.17.
In the Attribute option select “onsubmit” and in the Value write “return validateForm()” as shown in figure
2.17. Press OK button.
Now, open the source view. Add the script inside the <head> tag as shown in figure 2.18.
<html>
<head>
<meta content="text/html; charset=ISO-S859-1"
http-equiv="content-type">
<title>javascript example2 far form properties</title>
<script>
function validateForm()
{
var x=document.js2.name.value;
if (x==null | | x=="")
{
alert{"Please Enter The Name");
document.js2.name.focus();
return false;
}
}
</script>
</head>
<body style="height: 142px;">
<form onsubmit="return validateForm()" method="post" action="js2.html"
name="js2"><br>
<br>
<label>Name </label>
<input name="name"> <br>
<br>
<br>
<input name="submit" value="submit"
type="submit"> <br>
</form>
</body>
</html>
Figure 2.18 : JavaScript in source view
As seen in the script tag of figure 2.18 we have defined :
a function validateForm() a variable x
a conditional statement if built-in function alert()
an object named document a method named focus
Give Ctrl+S.
Open the file named js2.html in Mozilla Firefox and study the output.
Std.-12 : Computer Darpan – ‘Kumar’ 59
Likewise, submit event will have an event handler Document Object Model :
as onsubmit(). (document.js1.name.value)
In our example, we want the validation to be Sometimes, you may want to use JavaScript to
done when the user clicks the submit button i.e. control the web browser.
on the “submit” event.
For example, you may want to change the
So, we need to use the onsubmit() event handler. webpage or control the elements of the webpage.
Therefore, in figure 2.18 we had added an event To control the web browsers window or the
handler onsubmit(). webpage we use the Browser Object Model (BOM).
This event handler will call the function All browsers are split into different parts or
validateForm(). objects that can be accessed using JavaScript,
The function will return a value either True or These parts are known as the Browser Object
False depending on whether the name field has a Model or BOM.
value or null (no value). On the top of this browser hierarchy is the
Variable : Window object as shown in figure 2.19.
In our example, inside the function
validateForm() we have a statement
var x=document.js1.name.value
We have declared a variable named x.
A variable is a container for storing data.
Remember, that the variables in JavaScript are
also case sensitive. So, a variable “x” is not the
same as variable “X”.
The variables can store numbers, strings or text.
In JavaScript, we can declare a variable using var
keyword.
Figure 2.19 : Hierarchy of browser object
For example,
It represents the hierarchy of entire browser along
var x=3; .
with the toolbar menu, status bar, webpage and
var y=”Hello”;
many more.
var z=”Hello Students”;
We can use the properties and the methods of
If statement : objects in the browser object model to change the
You must be familiar with conditional statement if. window or elements displayed in the browser.
The conditional statement if is used to change We do not have to create an object in a browser
the flow of the program. object model; they are created automatically
The if statement evaluates an expression to when the browser opens the webpage.
validate specific condition. The top level object in the browser object model
If the condition is true, then the program enters is Window object. Window object represents the
in if block and executes the statements inside it. browser window or individual frame within the
In our example, we have used the if statement to window.
check whether the variable x is having null value It is created automatically by the browser.
or not. The window object is the global object as it
If the variable x is having null value then the contains all the other objects of the browser
statements inside the if block will be executed. object model within it.
Std.-12 : Computer Darpan – ‘Kumar’ 61
For example, window object contains the Keep the Name field empty and press the Submit
document object. button. You will see an alert message as shown in
We use the methods and properties of the window figure 2.21 appear on the screen.
object to control the web browser window, while
the methods and properties of document object
are used to control the webpage.
The document object is the most important
object in the browser object model.
It is used to represent the webpage displayed in
the browser.
All the elements of the webpage like forms,
images, links and others are contained within the
Figure 2.21 : Alert Message for empty name field
document object.
The alert message is the result of the script that
For example, the form object which is used by
we had written in the source view.
JavaScript to represent forms are created using
This is the validation that we have provided in the
the <form> element within the document object.
form using JavaScript.
Just as the document object contains a form
Thus, a form having more fields can be validated
object, similarly the form object contains element
to check if the user has kept any of the fields
object.
empty.
The element object is used to reference each
You must have observed while filling forms on
element in a form. The element objects can be Internet, some fields are marked with a red color
radio, text, checkbox or any other object. asterisk mark “*”.
The Focus Method : This is an indication to the user that it is a
In the script, we have also used a method named compulsory field which should not be kept
focus. empty.
It is used to apply focus on a particular element Using JavaScript, we can check the entry in such
of the form. fields and provide the alert message to the user.
Thus, after the user gets an alert message, calling Example – 5 :
the focus method, the cursor will be placed inside Let us now add another field in the form named
the element and the particular element will be “Pincode”.
highlighted. The validations which we will apply on this field
Here the name element will be focused. are :
Let us now open the file in the browser. User should not keep the field empty.
The output as shown in figure 2.20 will be visible Only numbers are allowed (characters are not
to us. allowed).
The Pincode should be 6 digits long.
If any of the validation is violated, the user will be
displaced an alert message.
Follow the steps given to create such a validation.
In Example-4 form name is js2, open it.
In the same form insert a label and a input field
for Pincode.
Figure 2.20 : Result in Browser
62 2. Cascading Style Sheets and Java script
In the source view, add the script as shown in figure. Thus, using if statement we check if y is; empty,
not a number or not equal to six digits.
<script>
If any of the condition is violated then the alert
function validateForm()
message will be displayed to the user.
{
Open the file in the browser.
var x=document.js2.name.value;
The output will be as shown in figure 2.23.
var y=document.js2.name.value;
if(x==null || x=="")
{
alert("Please Enter the Name");
document.js2.name.focus();
return false;
}
Figure 2.25 shows the script with three if conditions. Enter some numeric value less than 6 digits
length in the Pincode field and press the submit
<script>
button. This will show an alert message as shown
function validateForm()
in figure 2.27.
{
var x=document.js2.name.value;
var y=document.js2.pincode.value;
if (x==null || x=="")
{
alert("Please enter the Name");
document.js2.name.focus();
return false;
}
if (y=="")
{
alert("please enter the pincode properly");
document.js2.pincode.focus();
Figure 2.27 : Alert message to check length
return false;
} Example - 7 :
if (isNaN(y)) Let us take the “Registration Form” that we had
{ created in the Chapter l and add JavaScript to it.
alert("please enter a number"); To apply validations, we will make some simple
document.js2.pincode.focus();s changes in the form that are listed below :
return false;
Gender and Hobby field will not be kept initially
}
selected.
If (y.length>6 || y.length<6)
{ Address field has no initial text.
alert("please enter a six digits"); City field has an option “choose the city” whose
document.js2.pincode.focus(); value is -1.
return false; All the other options in the city field like
} Ahmedabad, Rajkot, Surat have values 1, 2, 3
} respectively.
</script> To make the above changes, open the form and
select the respective field in the form.
Figure 2.25 : JavaScript code to display
appropriate message
Open the file in the browser. Enter some
characters in the Pincode field and press the
submit button. This will show an alert message as
shown in figure.
Figure 2.26 : Alert message to check numeric value Figure 2.28 : Modified Registration Form
64 2. Cascading Style Sheets and Java script
if(document.form1.city.value=="-1")
{
alert("Please provide your city");
document.form1.city.focus();
return false;
Figure 2.30 : Advanced Property Editor }
}
Add the script shown in figure 2.31 inside the
</script>
<head> section as of the HTML.
Figure 2.31 : Validation of JavaScript
Std.-12 : Computer Darpan – ‘Kumar’ 65
As seen in the script, we have initialized four Similarly, the checkboxes for the hobby field are
variables x, y, z and r. grouped by the name “hobby”.
In the statement var x=document.form1.
Thus, hobby is an array with three elements.
firstname.value.
The term form1 refers to the form name; term Just as we checked the gender using the if
firstname refers to the element name (the name condition, we check the hobby and if all the three
given to the input field “first name”). elements are false then no option is selected and
Thus, the user is displayed the alert message to select a
variable x stores the value of first name hobby and the focus is placed on the checkbox.
variable y stores the value of middle name For the city field, we check if the value is equal to
variable z stores the value of last name –1 (Note: –1 is kept as the value for option
variable r stores the value of address “choose the city”), in that case no option is
In the script, using the if condition, selected and the user is given an alert message.
variable x checks, if the first name is empty or Figure 2.32 to 2.35 shows some of the alert
not. messages displayed after the fields are left empty.
variable y checks, if the middle name is Thus, we learnt how to use JavaScript for form
empty or not.
validation and make the webpages more
variable z checks, if the last name is empty or interactive.
not.
variable r checks, if the address is empty or
not.
Gender : The radio buttons for gender field are
grouped by the name “gender”.
Thus, gender is an array with two elements.
The first element of the gender array is checked
by using the if condition with the statement
document.form1.gender[0].checked and the
second element of the array is checked using the
statement document.form1.gender[1].checked.
If both of them are false then no option is
selected by the user.
Thus, alert message is displayed and the focus is
placed on radio button. Figure 2.32 : Final Form
39) What is the use of JavaScript in a webpage ? 47) Generally it is preferred that the JavaScript
(A) To improve the design code should be placed in the .......... tag.
(B) To validate the forms. (A) <body> ..... </body> (B) <head> ..... </head>
(C) (A) and (B) both (C) <title> ..... </title> (D) <form> ..... </form>
(D) To change the modern format in a webpage 48) The .......... tag tells the browser to interpret all
40) .......... browser supports JavaScript. the text between the <script> tags as a script.
(A) Mozilla Firefox (B) Chrome (A) <body> (B) <head> (C) <script> (D) <form>
(C) Safari and Internet Explorer
49) In document.write(“HELLO DIVYAKANT SIR”),
(D) All of these
.......... is the method.
41) JavaScript can be used for a ...... in a webpage.
(A) document (B) write
(A) interactivity with the user
(C) HELLO STUDENT (D) none of these
(B) control the browser
(C) dynamically create HTML content 50) .......... is the correct command to display
(D) All of these something directly in the browser.
42) What type of a script is JavaScript ? (A) print.write ( ) (B) document.write ( )
(A) Application client side (C) display.write ( ) (D) write.document ( )
(B) Application server side 51) In document.write (“Enjoy Computer with
(C) For any webpage (D) All of these Divyakant Sir”); .......... is the object.
43) It is used to validate the data entered in the (A) document (B) write
HTML forms on the .......... before sending it to (C) saraswati (D) none of these
the server. 52) .......... symbol is optional in JavaScript.
(A) Server side (B) Client side (A) Colon(:) (B) Semicolon(;)
(C) HTML details (D) All of these
(C) Full stop(.) (D) Double quotes(“ “)
44) ....... can be checked in a form by using
53) What is the use of semicolon in JavaScript ?
JavaScript.
(A) Termination of statement
(A) Has the user left any required field empty ?
(B) Separation of statement
(B) Has the user entered a valid date ?
(C) Check whether contents of two fields are (C) Merge two statments
same or not ? (D) All of these
(D) All of these 54) Putting a ....... is a good programming practice.
45) .......... is not true for JavaScript. (A) colon (:) (B) @
(A) JavaScript is used to improve the design (C) (;) semi colon (D) #
(B) JavaScript contains the advanced 55) JavaScript statements are written in ..........
programming functionalities of languages brackets.
like C and Java. (A) < > (B) ( ) (C) { } (D) [ ]
(C) JavaScript validates the form 56) JavaScript statements can be grouped together
(D) Browsers like Chrome and Safari support in a .......... .
JavaScript (A) function (B) routine
46) .......... is true for JavaScript. (C) (A) or (B) (D) main block
(A) JavaScript is not a case sensitive language 57) Functions are defined with .......... keyword.
(B) The lines between the <script> and </script> (A) function (B) main
tag contains the JavaScript code (C) void main (D) func
(C) JavaScript is not included with HTML 58) .......... is the inbuilt function.
(D) JavaScript can not be inserted directly as an (A) Validate Form ( ) (B) alert
independent part in a webpage (C) form ( ) (D) none of these
ANSWER (39 - C) (40 - D) (41 - D) (42 - A) (43 - B) (44 - D) (45 - B) (46 - B) (47 - B) (48 - C)
(49 - B) (50 - B) (51 - A) (52 - B) (53 - B) (54 - C) (55 - C) (56 - C) (57 - A) (58 - B)
Std.-12 : Computer Darpan – ‘Kumar’ 67
59) Function is also known as .......... . 71) When user leaves a page, it is known as ...... event.
(A) routine (B) dynaset (C) task (D) procedure (A) unload (B) reset (C) error (D) blur
60) What is the use of alert() function ? 72) When mouse pointer is over the particular
(A) Accepts the content element, it is known as .......... event.
(B) Displays the content (A) select (B) mouseover
(C) (A) and (B) both (C) submit (D) load
(D) Accepts the data from the user 73) When document or image is loaded, it is known
61) .......... type of function is alert(). as .......... event.
(A) User defined (B) Built-in (A) load (B) select (C) click (D) submit
(C) Simple and easy (D) None of these 74) .......... is the event handler.
62) .......... statement is false about the function. (A) HTML Code (B) JavaScript Code
(A) Function can be called from any location in (C) DHTML Code
the source code (D) Java programming Code
75) .......... specific code is executed when a
(B) Function can only be defined in the body
particular event occurs.
section
(A) JavaScript (B) HTML
(C) Function only accepts the value given in its
(C) Java (D) DHTML
brackets
76) .......... is not an event handler.
(D) Function can be called by its name
(A) onclick( ) (B) onsubmit( )
63) Values given in the function are known as ........
(C) load( ) (D) onfocus( )
(A) variable (B) arguments 77) .......... is not an event handler.
(C) parameters (D) (B) or (C)
(A) blur (B) exit (C) reset (D) error
64) .......... statement is used to stop the execution
78) .......... is the name of event handler for the
of the function and return a specific value.
‘click’ event.
(A) end (B) exit (C) return (D) pause (A) Click( ) (B) Onclick ( )
65) When user clicks the submit button is known (C) On Click { } (D) OnClick [ ]
as .......... 79) .......... is the name of event handler for the
(A) events (B) event handler ‘submit’ event.
(C) work (D) process (A) OnSubmit() (B) Submit()
66) .......... is used to make interactive page which (C) onsubmit() (D) onSubmit()
respond to the event done by user. 80) .......... means the storage for storing values.
(A) HTML (B) DHTML (A) Variable (B) Parameter
(C) Java Programming (D) JavaScript (C) Identifier (D) All of these
67) .......... is created by the interaction of user and 81) .......... is used to declare variables in JavaScript.
webpage. (A) Var (B) var (C) VAR (D) vr
(A) Events are created 82) .......... is true for the variables in JavaScript.
(B) Event handler is created (A) Variable is case sensitive
(C) Process is done (D) Work is done (B) Number, string or characters can be stored
68) When loading of image is cancelled, it is known in variable
as .......... event. (C) Variables can be declared by using var keyword
(A) blur (B) abort (C) load (D) unload (D) All of these
69) When an error occurs while loading an image, 83) .......... is the use of if statement.
it is known as .......... event. (A) Conditional statement to change the flow of
(A) unload (B) blur (C) error (D) reset program
70) When element such as button becomes active, (B) Checks for the validation of condition
it is known as .......... event. (C) (A) and (B) both
(A) active (B) blur (C) focus (D) select (D) For non-conditional work
ANSWER (59 - A) (60 - C) (61 - B) (62 - B) (63 - D) (64 - C) (65 - A) (66 - D) (67 - A) (68 - B)
(69 - C) (70 - C) (71 - A) (72 - B) (73 - A) (74 - B) (75 - A) (76 - C) (77 - B) (78 - B)
(79 - C) (80 - A) (81 - B) (82 - D) (83 - C)
68 2. Cascading Style Sheets and Java script
104) NaN stands for .......... . 106) isNaN(“DivyakantSir”) will give .......... output.
(A) Number and Number (A) true
(B) Not a Number (B) false
(C) Not a Numeric (C) error
(D) Numeric and Number (D) hello
105) isNaN(123) will give .......... output. 107) .......... element is used to write script in HTML.
(A) true (A) <head> ... </head>
(B) false (B) <script> ... </script>
(C) error (C) <scr> ... </scr>
(D) 123 (D) <Body> ... </Body>
Textual Exercise
(1) State the purpose of Cascading Stylesheets. 3) Which of the following are two main parts
Ans. For answer see topic no. 2.1 of CSS rule ?
(2) Why should we keep the style and the content (A) Selector, declaration
of a webpage separate ? (B) Select, declaration
Ans. For answer see topic no. 2.1 (C) Selector, declare
(3) Explain the syntax of CSS. (D) Selection, declaration
Ans. For answer see topic no. 2.2 4) Which of the following is an HTML element
(4) State the advantages of CSS. on which style can be applied ?
Ans. For answer see topic no. 2.3 (A) Declaration
(5) List the disadvantages of CSS. (B) Selector
Ans. For answer see topic no. 2.4 (C) Select
(6) Why do we use JavaScript in HTML pages ? (D) Declare
Ans. For answer see topic no. 2.5 5) Which of the following is the syntax of CSS ?
(7) How does an HTML page identify the (A) select {property : value}
JavaScript code ? Give an example. (B) selector {value : property}
Ans. For answer see figure no. 2.13 (C) selector {property : value}
(8) Choose the most appropriate option from (D) selection {property : value}
those given below : 6) Which of the following has developed
1) Which of the following allows specifying JavaScript ?
styles for the visual elements of the website ? (A) Yahoo
(A) Cascading Stylesheets (B) Google
(B) Web page (C) Wikipedia
(C) Form (D) Netscape
(D) Animation 7) Which of the following is a scripting
2) Which of the following is known as special language that allows adding programming
symbol in the syntax of CSS ? to webpages ?
(A) Rules (B) Selector (A) Action script (B) JavaScript
(C) Declaration (D) Input (C) HTML (D) CSS
70 2. Cascading Style Sheets and Java script
8) Which of the following is a scripting language 14) Which of the following is not an event ?
that is simple, lightweight programming (A) Abort (B) Mouseover
language that does not contain advanced
(C) Set (D) Load
programming functionalities ?
15) Which of the following is a container for
(A) JavaScript (B) HTML
storing data ?
(C) C (D) Java
(A) Variable (B) Integer
9) Which of the following tag is used to insert
JavaScript code into an HTML page ? (C) Event (D) Event handler
(A) <script>... <script> 16) Which of the following stands for BOM ?
(B) <script>... </script> (A) Browser Of Model
(C) <script>... <//script> (B) Browser Object Model
(D) </script>... </script> (C) Browser Object Modelling
10) Which of the following symbol signifies the (D) Browse Object Model
start and end of a JavaScript block ? 17) Which of the following is the top level
(A) Semicolon (B) Square bracket object in the browser object model ?
(C) Curly bracket (D) Round bracket (A) Window
11) Which of the following is a reusable block (B) Document
of code that performs a particular task ? (C) Page
(A) Array (B) Code (D) Location
(C) Program (D) Function
18) Which of the following stands for NaN ?
12) Which of the following statement is used to
(A) Not a Numeric
return a value in a function ?
(B) Not a Number
(A) Return (B) Function
(C) Not a Noun
(C) Select (D) Send
(D) Not an Numeric
13) Which of the following is generated by the
browser due to interaction between the Ans. : (1 - A), (2 - A), (3 - A), (4 - B), (5 - C),
user and the webpage ? (6 - D), (7 - B), (8 - A), (9 - B), (10 - C),
(A) Function (B) Response (11 - D), (12 - A), (13 - C), (14 - C), (15 – A),
(C) Event (D) Value (16 - B), (17 - A), (18 - B)
Laboratory Exercise
(1) Create a CSS for H1 as per the given rules and (1) Fields should not be empty.
apply it on the text. (2) Only numbers are allowed in the phone field.
(3) The phone number should be 10 digits long.
(1) Font : Times New Roman
Ans. This type of webpage has been discussed in our
(2) Color : red
example-2. So try yourself.
(3) Case : Lowercase
(1) Field should not be empty
(4) Font style : Italic (2) Only digits should be there in this field
(5) Alignment : Centre (3) Only 10 digits should be there in mobile no.
(6) Text decoration : Underline (3) Give validation to the student’s personal details
(7) Background color : Light Grey form created in chapter 1.
(8) Border : Dotted Ans. This type of webpage we have discussed in the
Ans. This type of webpage has been discussed in our chapter. So try yourself.
example-1. So try yourself. (4) Give validation to the feedback form created in
(2) Create a form with fields: name, e-mail address, chapter 1.
phone number and submit button. Give validation Ans. This type of webpage we have discussed in the
as given below : chapter. So try yourself.