Web Programming I | Preboard Solutions

3rd Semester

Morgan

Group A

  1. Why is <head> tag used in HTML file?
    The <head> tag is used in HTML file to contain specific information about a web page, referred as metadata, which includes things like the title of the document (which is mandatory), scripts or links to scripts, and CSS files.
    E.g.
    <head>
    <title> Title </title>
    </head>
  2. What is the use of <span> element?
    <span> element is used to group inline elements. When used together with CSS, <span> element can be used to style part of the text.
    E.g. <h2> My <span style=”color:red”> Important </span> Heading </h2>
  3. Write a source code to create an image button.
    <form>
    <input type=”image” name=”imgbutton” src=”image.jpg”>
    </form>
    Height and width of the image button can also be added using height and width attribute.
  4. How link from one part of the page to another part of the same page is created?
    Link from one part of the page to another part of the page can be created by using destination anchor.  The link starts at the source anchor and points to the destination anchor.
    E.g.

    <a href=”#bottom”> Go to bottom /a>
    ……….
    ……….
    <h2 id=”bottom”> Bottom of the page </h2>
  5. List the possible values of overflow property.

  6. How array is created in
    – Using array literals: var cars = [“Saab”, “Volvo”, “BMW”];
    – Using new keyword: var cars = new Array(“Saab”, “Volvo”, “BMW”);
  7. How the text-shadow property is used?
    The text-shadow property uses color followed by three lenghts;
    E.g.
    .dropshadow{
    text-shadow: #999999 10px 10px 3px;
    }After the color has been specified, the first two lengths specify how far from the original  text the drop shadow should fall, while the third shadow specifies how blurred the drop shadow should be.
  8. What do you mean by site-map?
    Site-map allows site visitors to easily navigate a website and is a bulleted outline text version of the site navigation. Site visitors can go to the Sitemap to locate a topic they are unable to find by searching the site or navigating through the site menus.
  9. What is the use of <blockquote> element?The <blockquote> tag specifies a section that is quoted from another source. The blockquote element is used to indicate the quotation of a large section of text from another source.
  10. What is the use of substring()?
    The use of substring() is to extract the characters from a string, between two specified indices, and return the new sub string. This method extracts the characters in a string between “start” and “end”, not including “end” itself.
    E.g.
    var str = “Hello world!”;
    var res = str.substring(4, 1);

 

Asian School of Management and Technology

Group A

  1. What is JavaScript?
     JavaScript is a very popular scripting language used mostly for Web development which can update and change both HTML and CSS.
  2. What does trim() function do?
    The trim() function is used to remove any extra white spaces from a string. It does not change the content of the string.

    Eg: var str = ”       Hello World!        “;
    alert(str.trim());Output: Hello World!
  3. What is absolute URL?
    The absolute URL refers to the address of a document or page which consist a large amount of information about the document’s

    Eg: https://www.google.com / is an example of an absolute URL of the site Google.
  4. Write JavaScript code to display current date.
    The program is as:
    …..
    var a = new Date();
    alert(a);
    ….
  5. What do you mean by shorthand properties? Write an example.
    Shorthand properties are the CSS properties, that lets us set the values of multiple CSS properties simultaneously.

    Eg: margin-top:5px; margin-right:10px; margin-bottom:3px; margin-left:6px;
    can be written as margin: 5px 10px 3px 6px;
  6. Write two differences between entry control loop and exit control loop.
    The differences are as follows:

    Entry Control Loop

    Exit Control Loop

    Test condition is checked first, and then loop body will be executed. Loop body will be executed first, and then condition is checked.
    If Test condition is false, loop body will not be executed. The for loop and while loop are the examples of Entry Controlled Loop. If Test condition is false, loop body will be executed once. The do while loop is the example of Exit controlled loop.
  7. Define HTML.
    HTML(Hypertext Markup Language) is a standard markup language used for creating web pages and web applications.

  8. Write output: document.write(2+10+“2”):
    The output of the above program is 122.
  9. Which CSS property is used to control the scrolling image in the
    Background-attachment property is used to control the scrolling image in the background.
  10. What does parseInt() function do?
    The use of parseInt() function is to return the integer equivalent of a string by parsing it.

 

PRIME College

GROUP C

  1. What are the uses of CSS? Explain combinators with example.
    – CSS is the language for describing the presentation of Web pages, including colors, layout, and fonts. It allows one to adapt the presentation to different types of devices, such as large screens, small screens, or printers. CSS is independent of HTML and can be used with any XML-based markup language. The separation of HTML from CSS makes it easier to maintain sites, share style sheets across pages, and tailor pages to different environments.
  • CSS combinators are explaining the relationship between two selectors. CSS selectors are the patterns used to select the elements for style purpose. A CSS selector can be a simple selector or a complex selector consisting of more than one selector connected using combinators.
  • There are four types of combinators available in CSS which are discussed below:
    • General Sibling selector (~)
    • Adjacent Sibling selector (+)
    • Child selector (>)
    • Descendant selector (space)
  1. General Sibling selector (~)
    div ~ p{
    color: #009900;
    font-size:32px;
    font-weight:bold;
    margin:0px;
    text-align:center;
    }
  2. Adjacent Sibling selector (+)
    div + p{
    color: #009900;
    font-size:32px;
    font-weight:bold;
    margin:0px;
    text-align:center;
    }
  3. Child selector (>)
    div > p{
    color: #009900;
    font-size:32px;
    font-weight:bold;
    margin:0px;
    text-align:center;
    }
  4. Descendant selector (space)
    div   p{
    color: #009900;
    font-size:32px;
    font-weight:bold;
    margin:0px;
    text-align:center;
    }

2. Explain different HTTP methods. Why the web form should be validated? Write a JavaScript program to check whether user entered number is Prime or not.

The most common HTTP methods are GET and POST.

The GET method:

    • GET is used to request data from a specified resource.
    • GET requests can be cached
    • GET requests remain in the browser history
    • GET requests can be bookmarked
    • GET requests should never be used when dealing with sensitive data
    • GET requests have length restrictions
    • GET requests is only used to request data (not modify)

The POST method:

    • POST is used to send data to a server to create/update a resource.
    • The data sent to the server with POST is stored in the request body of the HTTP
    • POST requests are never cached
    • POST requests do not remain in the browser history
    • POST requests cannot be bookmarked
    • POST requests have no restrictions on data length

The web form should be validated in order to take valid data from the user. It also helps us to ensure that users fill out forms in the correct format, making sure that submitted data will work successfully with our applications.

Source code:

<!DOCTYPE html>

<html>

<head>

<title></title>

<script type=”text/javascript”>

function check()

{

var i;

var count=0;

var n1;

var c=0;

n1=document.getElementById(‘prime’).value;

for(i=2;i<n1;i++)

{

if(n1%i==0)

{

c+=1;

}

}

if(c==0)

{

alert(“The entered no. is prime”);

}

else

{

alert(“The entered no. is not Prime”);

}

}

</script>

</head>

<body>

<label>Enter Number </label><input type=”number” name=”number” id=”prime”>

<button onClick=”check()”>Check</button>

</body>

</html>

 

SDC

Group C

  1. Explain form validation with example.

Validation

Form validation normally used to occur at the server, after the client had entered all the necessary data and then pressed the Submit button. If the data entered by a client was incorrect or was simply missing, the server would have to send all the data back to the client and request that the form be resubmitted with correct information. This was really a lengthy process which used to put a lot of burden on the server.

JavaScript provides a way to validate form’s data on the client’s computer before sending it to the web server. Form validation generally performs two functions.

    • Basic Validation− First of all, the form must be checked to make sure all the mandatory fields are filled in. It would require just a loop through each field in the form and check for data.
    • Data Format Validation− Secondly, the data that is entered must be checked for correct form and value. Your code must include appropriate logic to test correctness of data.

Simple Form Validation

<html>

<head>

<script Language=”JavaScript”>

function Form1_Validator(theForm)

{

if (theForm.name.value == “”)

{

alert(“You must enter an name.”);

return (false);

}

// require at least 3 characters be entered

if (theForm.name.value.length < 3)

{

alert(“Please enter at least 3 characters in the \”name\” field.”);

return (false);

}

}

</script>

</head>

<body>

<form method=”POST” action=”hompage.html” onsubmit=”return Form1_Validator(this)” name=”theForm”>

name:   <input type=”text” size=”15″ maxlength=”15″ name=”name”><br>

                Not blank, at least 3 characters<br>

<input type=”submit” name=”Submit” value=”Submit”>

                </form>

</body>

</html>

 

2. Write short notes on

1.Internet Explorer Box Mode Bug :

The IE Box model is similar except for one important difference: paddings and borders are not included in the calculation:

total width = margin-left + width + margin-right

This means that if the element also has horizontal padding and/or borders, the actual content area will shrink to make room for them

2.HTTP get and post method :

            The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute).

The form-data can be sent as URL variables (with method=”get”) or as HTTP post transaction (with method=”post”).

Notes on GET:

    • Appends form-data into the URL in name/value pairs
    • The length of a URL is limited (about 3000 characters)
    • Never use GET to send sensitive data! (will be visible in the URL)
    • Useful for form submissions where a user want to bookmark the result
    • GET is better for non-secure data, like query strings in Google

Notes on POST:

    • Appends form-data inside the body of the HTTP request (data is not shown is in URL)
    • Has no size limitations
    • Form submissions with POST cannot be bookmarked
    1. Generated Contents:

Content specified in a stylesheet can consist of text or images. You specify content in your stylesheet when the content is closely linked to the document’s structure.
Text content

CSS can insert text content before or after an element. To specify this, make a rule and add ::before or ::after to the selector. In the declaration, specify the content property with the text content as its value.

To add an image before or after an element, you can specify the URL of an image file in the value of the content property.