Академический Документы
Профессиональный Документы
Культура Документы
Answer :
<!DOCTYPE html>
<html>
<head>
<title>Table</title>
</head>
<body>
<table border="1" width="100%">
<tr>
<td colspan="4">A</td>
</tr>
<tr>
<td rowspan="2">B</td>
<td colspan="2">C</td>
<td>D</td>
</tr>
<tr>
<td>E</td>
<td>F</td>
<td>G</td>
</tr>
<tr>
<td>H</td>
<td>I</td>
<td colspan="2">J</td>
</tr>
</table>
</body>
</html>
Q2.Explain CSS and its type with example.
-CSS Stands for cascading Style sheet
-CSS describe how HTML elements are to be displayed on the screen.
-CSS can control the layout of multiple web pages all at once.
-Using CSS we can decorate web sites with different fonts,color,graphics,etc.
Advantages :
- Saves time
-Easy to change
-Keep consistency
-Give you more control over layout
-Use styles with JavaScript => DHTML
-Make it easy to create a common format for all the Web pages
Types of CSS:
1.Inline CSS
2. Embedded or internal CSS
3.External CSS
1.Inline CSS :
-Add styles to each tag within the HTML file
-Use it when you need to format just a single section in a web page
Example :
<h1 style=“color:red; font-family: sanssarif”>IU</h1>
<link href=“mystyle.css”
rel=“stylesheet”
type=“text/css” />
Q3. What is Document Object Model? Explain the various objects in Document Object
Model.
The DOM is a W3C (World Wide Web Consortium) standard.
The DOM defines a standard for accessing documents:
"The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows
programs and scripts to dynamically access and update the content, structure, and style of a
document."
The W3C DOM standard is separated into 3 different parts: Core DOM - standard model for all
document types .
XML DOM - standard model for XML documents .
HTML DOM - standard model for HTML documents .
When a web page is loaded, the browser creates a Document Object Model of the page.
Document Object:
If you want to access any element in an HTML page, you always start with accessing the document
object.
Method Description :
document.getElementById(): Finding an element by element id document.getElementsByTagNam
e(): Finding elements by tag name document.getElementsByClassNa me(): Finding elements by class
name .
document.forms[]: Finding elements by HTML element objects.
For example,
document.getElementById() :
document.getElementById()- Finding an element by element id
<html>
<body><p id="intro">Hello World!</p>
<script>
txt=document.getElementById("intro").innerHTML; alert(txt);
</script>
</body>
</html>
Q4.Give the full names of the following acronym:
(1) WML (2) DOM (3) DHTML (4) ISP (5) XML
(6) HTTP (7) XSL (8) FTP (9) CGI (10) WAP
(11) DTD (12) RSS (13) TCP (14) SOAP
Types of list
1.Ordered List
2.Unordered List
3.Description List
1.Ordered List :
- Used to display information in a numeric order.
-Using type attribute we can set different numbers.
- The syntax for creating an ordered list is:
<ol>
<li>Item 1</li>
<li>Item 2</li>
</ol>
Where ol = orederlist
Li = list item
2.Unordered List :
- list items are not listed in a particular order.
-The syntax for creating an unordered list is:
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
Where ul = onordered list
Li=list item
3.Description List :
-Description list is used to describe various terms
-The tag is supported in all major browsers.
- Definition and Usage
-The <dl> tag defines a description list.
-The <dl>tag is used in conjunction with <dt>(defines terms/names) and <dd>
(describes each term/name).
Syntax :
<dl>
<dt>Coffee</dt>
<dd>Black hot drink</dd>
<dt>Milk</dt>
<dd>White cold drink</dd>
</dl>
Q6. Differentiate following.
a.HTML and XHTML
b.GET and POST
a.HTMLvs XHTML
HTML XHTML
1.HTML is main markup language for creating 1.XHTML is a family of XML markup language
web pages and other information that can be that mirror or extend versions of the widly used
displayed in a web browser. HTML language in which web pages are
written.
2.Extension : .html, .html 2.Extension : .xhtml , .xml , .html, .htm
3.Internet Media Type : text/html 3.Internet Media Type :application/xhtml+xml
4.Type of Format: Markup language
4.Type of Format : Document file format 5. Stands for: Extensible HyperTextMarkup
5. Stands for: HyperTextMarkup Language Language
6. Function: Web pages are written in HTML. 6. Function: Extended version of HTML that is
7. Versions: HTML 2, HTML 3.2, HTML 4.0, stricter and XML-based
HTML 5 7. Versions: XHTML 1, XHTML 1.1, XHTML
2, XHTML 5
b.GETvs POST
GET POST
1.Parameter remain in browser history because 1.Parameter are nit saved in browser history.
they are part of the URL.
2.Can be bookmarked. 2.Cannot be bookmarked.
3.Easier to hack. 3.Difficult to hack
4.Only ASCII Characters allowed. 4.Norestriction.Binary Data is also allowed.
5.GET is less secure compared to the post 5.POST is a little secure than GET because the
because data sent is part of the URL. parameter are not stored ib browser history.
Q.7 what is an HTML form? Discuss the different form attributes and design a simple
form to register for a new semester.
Ans:
An HTML form is a section of a document which contains controls such as text fields, password
fields, checkboxes, radio buttons, submit button, menus etc.
An HTML form facilitates the user to enter data that is to be sent to the server for processing.
HTML forms are required if you want to collect some data from of the site visitor.
HTML forms are required if you want to collect some data from of the site visitor.
For example,If a user want to purchase some items on internet, he/she must fill the form such as
shipping address and credit/debit card details so that item can be sent to the given address.
Attributes:
Here are few attributes that’s use in form.
Action
Method
Name
Action: After submit the form, details should be go to server side. Action is an attribute through which
we can transfer the control to the server side.
action=”server_url”
method: details go to the server side. Method is an attribute through which method details should go
to the server side. It has two values get & post.
Name: name attribute gives a name to form which we can use future in javascript.
Register.html:
<!DOCTYPE html>
<html>
<head>
<title>Register</title>
</head>
<body>
<form name="myform">
Name :
<br />
<input type="text" name="name" >
<br />
<br />
semester :
<br />
<br />
<input type="text" name="semester">
<br />
<br />
Email :
<br />
<br />
<input type="text" name="email">
<br />
<br />
Phone Number :
<br />
<br />
<input type="text" name="number" >
<br />
<br />
Pin Code :
<br />
<br />
<input type= "text" name="pin" >
<br />
<br />
Gender:
<input type= "radio" name="radio" >male
<input type= "radio" name="radio" >female<br/>
<button type="button" value="Submit">Submit</button>
</form>
</body>
</html>
Output:
Q.8 what do you mean by meta tag? Explain with example.
Ans:
The <meta> tag provides metadata about the HTML document. Metadata will not be displayed on the
page, but will be machine parsable.
Meta elements are typically used to specify page description, keywords, author of the document, last
modified, and other metadata.
The metadata can be used by browsers (how to display content or reload page), search engines
(keywords), or other web services.
The content attribute MUST be defined if the name or the http-equiv attribute is defined. If none of
these are defined, the content attribute CANNOT be defined.
Meta.html
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>Hello,User</h1>
</body>
</html>
Output:
Q-9)What is the role of cache and cookies in the browser?
ANS:
Cache:
Web browsers a can cache (store) pages for quick reviewing without having to request them again.
Each page has a Time to Live ( TTL), the time it is kept in the cache without going back and
reloading it.
A browser can be stopped from caching a page, if it support the „http-equiv‟ attribute.
To do this value „pragma‟ is assigned to http-equiv attribute.
Example –Force browser to ignore the cache page
<meta http-equiv=“pragma" content=“no-cache“/>
DISPLAY RESOLUTION
Display resolution always affect in visualization of web site.
While designing web site, you have to consider possible display resolutions of your expected
users client.
Display resolution is measured in terms of pixels. 800 X 600 and 1024 X 786 are common
resolutions.
Use relative size to page layout if possible to manage flexible width and height of your pages.
To make flexible design using HTML layout, divide page into no. of columns, where you can
set certain columns with variable width.
h1,h2,h3
{
font-size:120%
}
p.arial
{
font-family:Ariel;
font-weight:bold;
}
body
{
background-color:yellow;
background-image:url(apple.jpg);
}
Step 2: Create an HTML document which makes use of the external style sheet created in above step.
<html>
<head>
<link rel=”stylesheet” type=”text/css” href=”ex1.css”/>
</head>
<body>
<h1>This text is created using header tag.</h1>
<h2>This text is also created using header tag.</h2>
<p class=”arial”>Now the para is created having the font of type Arial. This text is in bold.
The background is yellow colored having the image of apple over it.
</p>
</body>
</html>
Q 13 Write a JavaScript, that uses a loop, that searches a word in sentence held in an
array, returning the index of the word.
<html>
<head>
<script type=”text/javascript”>
function Search(form1)
{
var Sentence=form1.input.value;
var pattern=prompt(“Enter the word to be searched for:”,””);
alert(pattern);
temp=Sentence.split(“ “);
for(i=0;i<temp.length;i++)
{
if(temp[i]==pattern)
{
alert(“The word is at position:”+(i+1));
}
}
}
</script>
</head>
<body>
<form name=”form1”>
<b>Enter the sentence</b>
<input type=”text” name=”input”><br/>
<input type=”button” value=”Click me” onclick=”Search(form1)”>
</form>
</body>
</html>
Q 14 What is javascript event? List out the major events and show use of at least one
event by writing javascript code.
Event is activity that represents a change of the state. For example mouse clicks, pressing a
particular key of the keyboard represent the events. Such events are called the intrinsic events.
Event handler is a script that gets executed in response to these events. Thus event handler
enables the web document to respond the user activities through the browser window.
Events are specified in lowercase letters and are case sensitives.
List of events:
XSL
HTML uses predefined tags. The meaning of and how to display each tag is well understood.
XML does not use predefined tags, and therefore the meaning of each tag is not well understood.
A <table> element could indicate an HTML table, a piece of furniture, or something else - and
browsers do not know how to display it!
XSLT
XSLT is a language for transforming XML documents into XHTML documents or to other XML
documents.
What is XSLT?
XSLT is used to transform an XML document into another XML document, or another type of
document that is recognized by a browser, like HTML and XHTML. Normally XSLT does this by
transforming each XML element into an (X) HTML element.
With XSLT you can add/remove elements and attributes to or from the output file. You can also
rearrange and sort elements, perform tests and make decisions about which elements to hide and
display, and a lot more.
A common way to describe the transformation process is to say that XSLT transforms an XML
source-tree into an XML result-tree.
XSLT uses XPath to find information in an XML document. XPath is used to navigate through
elements and attributes in XML documents.
In the transformation process, XSLT uses XPath to define parts of the source document that should
match one or more predefined templates. When a match is found, XSLT will transform the matching
part of the source document into the result document.
Example:
XML CODE:
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
<cd>
<artist>Gary Moore</artist>
<country>UK</country>
<company>Virgin records</company>
<price>10.20</price>
<year>1990</year>
</cd>
<cd>
<title>Eros</title>
<artist>Eros Ramazzotti</artist>
<country>EU</country>
<company>BMG</company>
<price>9.90</price>
<year>1997</year>
</cd>
</catalog>
XSLT Code:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<trbgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td><xsl:value-of select="catalog/cd/title"/></td>
<td><xsl:value-of select="catalog/cd/artist"/></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Result:
Q.16 Develop XML document that will hold player (Like Cricket) collection with field
for player-name, age, batting-average and highest-score, write suitable document type
definition and schema for the XML
ANSWER:
CricketTeam.xml
<?xml version='1.0' encoding='UTF-8' ?>
<CricketTeam>
<Team country='India'>
<player>Sachin</player>
<age>40</age>
<batting_average>53.78</batting_average>
<highest_score>200</highest_score>
</Team>
<Team country='Australia'>
<player>smith</player>
<age>26</age>
<batting_average>60.18</batting_average>
<highest_score>200</highest_score>
</Team>
XML SCHEMA:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema>
<xs:element name="CricketTeam">
<xs:complexType>
<xs:sequence>
<xs:element name="Team" type="xs:string"/>
<xs:complexType>
<xs:sequence>
<xs:element name="country" type="xs:string"/>
<xs:element name="player" type="xs:string"/>
<xs:element name="age" type="xs:string"/>
<xs:element name="batting_average" type="xs:string"/>
<xs:element name="highest_score" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Q 17 Explain cookies in PHP.
Cookies:
setcookie(name,value,expire_period,path,domain)
Following is a simple PHP document which illustrates how to set the cookies-
PHP Document(CookieSetDemo.php)
<?php
$Cookie_period=time()+60*60*24*30;
setcookie("Myname", "Kruti",$Cookie_period);
?>
Note that you have got the blank screen it indicates that the cookie is set. In above PHP document we
have set the PHP script for one month. Just observer the third parameter of the setcookie function.
Now you can retrieve the cookie and read the value to ensure whether or the cookie is set.
PHPDocument[CookieReadDemo.php]
<html>
<head><title>Reading Cookies</title>
<body>
<?php
if(isset($_COOKIE["MyName"]))
echo"<h3>Welcome".$_COOKIE[Myname"]."!!!</h3>";
else
echo"<h3>Welcome guest</h3>";
?>
</body>
</html>
Program Explanation:
The isset function is used for checking whether the cookies is set or not. Then using the $_COOKIE
the value of the cookie can be retrieved.
Q: 18 Explain session in PHP.
An alternative way to make data accessible across the various pages of an entire website is to use a
PHP Session.
A session creates a file in a temporary directory on the server where registered session variables and
their values are stored. This data will be available to all pages on the site during that visit.
The location of the temporary file is determined by a setting in the php.ini file called
session.save_path. Bore using any session variable make sure you have setup this path.
PHP first creates a unique identifier for that particular session which is a random string of 32
hexadecimal numbers such as 3c7foj34c3jj973hjkop2fc937e3443.
A cookie called PHPSESSID is automatically sent to the user's computer to store unique session
identification string.
When a PHP script wants to retrieve the value from a session variable, PHP automatically gets the
unique session identifier string from the PHPSESSID cookie and then looks in its temporary directory
for the file bearing that name and a validation can be done by comparing both values.
A session ends when the user loses the browser or after leaving the site, the server will terminate the
session after a predetermined period of time, commonly 30 minutes duration.
A PHP session is easily started by making a call to the session_start() function.This function first
checks if a session is already started and if none is started then it starts one. It is recommended to put
the call to session_start() at the beginning of the page.
Session variables are stored in associative array called $_SESSION[]. These variables can be accessed
during lifetime of a session.
The following example starts a session then register a variable called counter that is incremented each
time the page is visited during the session.
Make use of isset() function to check if session variable is already set or not.
Put this code in a test.php file and load this file many times to see the result −
<?php
session_start();
if(isset( $_SESSION['counter'] ) ) {
$_SESSION['counter'] += 1;
}else {
$_SESSION['counter'] = 1;
}
?>
<html><head>
</head><body>
</body></html>
A PHP session can be destroyed by session_destroy() function. This function does not need any
argument and a single call can destroy all the session variables. If you want to destroy a single session
variable then you can use unset() function to unset a session variable.
<?php
unset($_SESSION['counter']);
?>
Here is the call which will destroy all the session variables −
<?php
session_destroy();
?>
You don't need to call start_session() function to start a session when a user visits your site if you can
set session.auto_start variable to 1 in php.ini file.
There may be a case when a user does not allow to store cookies on their machine. So there is another
method to send session ID to the browser.
Alternatively, you can use the constant SID which is defined if the session started. If the client did not
send an appropriate session cookie, it has the form session_name=session_id. Otherwise, it expands to
an empty string. Thus, you can embed it unconditionally into URLs.
<?php
session_start();
if (isset($_SESSION['counter'])) {
$_SESSION['counter'] = 1;
}else {
$_SESSION['counter']++;
echo ( $msg );
?><p>
</p>
<?php
<?php
if(isset($_FILES['image'])){
$errors= array();
$file_name = $_FILES['image']['name'];
$file_size = $_FILES['image']['size'];
$file_tmp = $_FILES['image']['tmp_name'];
$file_type = $_FILES['image']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
$expensions= array("jpeg","jpg","png");
if(in_array($file_ext,$expensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if(empty($errors)==true) {
move_uploaded_file($file_tmp,"images/".$file_name);
echo "Success";
}else{
print_r($errors);
}
}
?>
<html>
<body>
<ul>
<li>Sent file: <?php echo $_FILES['image']['name']; ?>
<li>File size: <?php echo $_FILES['image']['size']; ?>
<li>File type: <?php echo $_FILES['image']['type'] ?>
</ul>
</form>
</body>
</html>
OUTPUT:
Q 21. Write a program to create a cookie and retrieve data of that cookie.
<!DOCTYPE html>
<?php
$cookie_name = "user";
$cookie_value = "John Doe";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
?>
<html>
<body>
<?php
if(!isset($_COOKIE[$cookie_name])) {
echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
echo "Cookie '" . $cookie_name . "' is set!<br>";
echo "Value is: " . $_COOKIE[$cookie_name];
}
?>
<p><strong>Note:</strong> You might have to reload the page to see the value of the cookie.</p>
</body>
</html>
Q. 22 Write a program to modify cookie value.
<!DOCTYPE html>
<?php
$cookie_name = "user";
$cookie_value = "Alex Porter";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
?>
<html>
<body>
<?php
if(!isset($_COOKIE[$cookie_name])) {
echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
echo "Cookie '" . $cookie_name . "' is set!<br>";
echo "Value is: " . $_COOKIE[$cookie_name];
}
?>
<p><strong>Note:</strong> You might have to reload the page to see the new value of the
cookie.</p>
</body>
</html>