Web Technology and Programming(161602) - Dec 2014/15

Q-1 (a) What is Cascading Style Sheet (CSS)? Explain different types of CSS with example.
What Is CSS?
When a browser reads a style sheet, it will format the HTML document according to the information in the style sheet.Most web pages are made from HTML, or hypertext markup language. This is the standard way to decorate plain web text with fonts, colors, graphic doodads, and hyperlinks (clickable text that magically transports the user somewhere else). But websites can get really big. When that happens, HTML is a very hard way to do a very easy thing. CSS (cascading style sheets) can make decorating web sites easy again!
Three Types of CSS
CSS comes in three types:
  • In a separate file (external)
  • At the top of a web page document (internal)
  • Right next to the text it decorates (inline)
External style sheets are separate files full of CSS instructions (with the file extension .css). When any web page includes an external stylesheet, its look and feel will be controlled by this CSS file (unless you decide to override a style using one of these next two types). This is how you change a whole website at once. And that's perfect if you want to keep up with the latest fashion in web pages without rewriting every page!

Web Technology and Programming - May 2012

Question 2

(b) What is an HTML form? How can you access the form data in php page? Explain with suitable example.

index.html

<html>

<head><title>HTML Form</title>
</head>

<body>

<form action="submit.php" method="post">
Name : <input type="text" name="name" /> <br />
Branch : <input type="text" name="branch" /><br />
Semester : <input type="text" name="semester" /><br />
<input type="submit" value="Submit">
</form>

</body>
</html>


submit.php

<?php
echo "We can access form data with $_POST variable.";
echo "<br />";
echo "Student Details :- ";
echo "<br />";
echo "Name : ".$_POST['name'];
echo "<br />";
echo "Branch : ".$_POST['branch'];
echo "<br />";
echo "Semester : ".$_POST['semester'];
?>

(b) Explain the use of HTML table element for designing the web page layouts with appropriate examples.

<html>

<head>
<title>Table example</title>
</head>

<body>

<table style="width:100%; float:left; height:auto;" border="1" bordercolor="#000000">

<tr> 
 <td colspan="3" style="width:100%; float:left; height:100px; text-align:center;">Header</td>
</tr>

<tr>
 <td style="width:20%; float:left; height:400px; text-align:center;">Left side bar</td>
 <td style="width:60%; float:left; height:400px; text-align:center;">Main content</td>
 <td style="width:20%; float:left; height:400px; text-align:center;">Right side bar</td>
</tr>

<tr>
 <td colspan="3" style="width:100%; float:left; height:50px; text-align:center;">Footer</td>
</tr>

</table>

</body>
</html>

Question 3

(a) How can you perform validation using JavaScript? Show the validation using JavaScript with simple form having name, phone number and email field.

<html>

<head>
<title>Javascript Validation</title>

<script type="text/javascript">

function validate(){
 var name = document.getElementById("name").value;
 var phone = document.getElementById("phone").value;
 var email = document.getElementById("email").value; 

 var phoneRegex = /^\d{10}$/;  

 if(name == "" && phone == "" || email == ""){
  alert("Please fill all fields!");
  return false;
 }
 else if(!phone.match(phoneRegex)){
  alert("Please enter 10 digit number!");
  return false; 
 }
 else{
  var atpos=email.indexOf("@");
  var dotpos=email.lastIndexOf(".");
  if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length){
    alert("Please enter valid e-mail address");
    return false;
  }
  else{
   alert("All fields are correct!");
   return true; 
  } 
 }
}

</script>

</head>
<body>

<form action="#" method="post" onSubmit="return validate()">
Name : <input type="text" id="name" /> <br />
Phone : <input type="text" id="phone" /><br />
Email : <input type="text" id="email" /><br />
<input type="submit" value="Submit">
</form>

</body>
</html>

(b) Show the use of window object for controlling your browser.

<html>

<head>
<title>window object example</title>

<script>

function openWin()
{
 myWindow=window.open("","","width=200,height=100");
 myWindow.document.write("<p>This is 'myWindow'</p>");
}

function closeWin()
{
 myWindow.close();
}

function moveWin()
{
 myWindow.moveBy(250,250);
 myWindow.focus();
}

function printpage()
{
 myWindow.print();
}

function myFunction()
{
 myWindow.resizeTo(500,500);
 myWindow.focus();
}

</script>
</head>

<body>

<input type="button" value="Open 'myWindow'" onclick="openWin()" />
<input type="button" value="Move 'myWindow'" onclick="moveWin()" />
<input type="button" value="Resize 'myWindow'" onclick="myFunction()" />
<input type="button" value="Print 'myWindow'" onclick="printpage()" />
<input type="button" value="Close 'myWindow'" onclick="closeWin()" />

</body>
</html>

(a) What is document object? Show its use in accessing the form elements with example.

Document Object : When an HTML document is loaded into a web browser, it becomes a document object.

<html>

<head><title>Document Object</title>

<script type="text/javascript">

function countFields(){
 alert(document.forms[0].length);
}

function getFields(str){
 alert(document.forms[0].elements[str].value);
}

</script>
</head>

<body>

<form action="#">
Name : <input type="text" name="name" /> <br />
Branch : <input type="text" name="branch" /><br />
Semester : <input type="text" name="semester" /><br />
<input type="submit" value="Submit" />
</form>

<input type="button" value="Count form fields" onClick="countFields()" />
<input type="button" value="Value of Name field"  onClick="getFields('name')"/>
<input type="button" value="Value of Branch field"  onClick="getFields('branch')"/>
<input type="button" value="Value of Semester field" onClick="getFields('semester')" />

</body>
</html>

Question 4

(a) Write a PHP program that receives the value of N using HTML form and displays the first N Fibonacci numbers as HTML list.

index.html 

<html>

<head><title>Fibonacci Numbers</title>
</head>

<body>

<form action="generate-fibonacci-series.php" method="post">
Number : <input type="text" name="number" /><br />
<input type="submit" value="Submit" />
</form>

</body>
</html>


generate-fibonacci-series.php

<?php

$a = -1;
$b = 1;
$number = $_POST['number'];

for($i=0;$i<$number;$i++){
 $c = $a + $b;

 echo $c." ";

 $a = $b; $b = $c;
}

?>

(b) Explain the PHP arrays with example.

Numeric Array

<?php

$numbers = array( 1, 2, 3, 4, 5);

foreach( $numbers as $value )
{
  echo "Value is $value <br />";
}

?>


Associative Arrays

<?php

$studentData = array( 
     "name" => "Jaydip Panchal", 
     "branch" => "Information Technology", 
     "semester" => 8
    );

echo "Students Data : <br />";

foreach($studentData as $key=>$value )
{
  echo "$key : $value <br />";
}

?>


Multidimensional Arrays

<?php
   
$marks = array( 
   "Jaydip Panchal" => array
   (
    "physics" => 35,     
    "maths" => 30,     
    "chemistry" => 39     
   ),
   "Arpan Patel" => array
           (
               "physics" => 30,
               "maths" => 32,
               "chemistry" => 29
           )
      );

foreach($marks as $key=>$val){
 echo "Marks for ".$key."<br />";
 foreach($val as $k=>$v){
  echo $k.":".$v."<br />";  
 }   
}   
?>

(a) What is session? How do php manage the sessions? Give an example to store and retrieve, your age as session variable

session : A session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application.

<?php session_start(); ?>

<html>

<head><title>Session management Example</title></head>

<body>

<?php

if(isset($_POST['submit'])){
 $_SESSION['age'] = $_POST['age']; 
}

if(isset($_SESSION['age']))
{
 echo "Your age = ". $_SESSION['age'];
}
else
{ 
 echo "Your age is not set";
}

?>

<form action="#" method="post">

Enter your age <input type="text" name="age" />

<input type="submit" value="Submit" name="submit" />

</form>

</body>
</html>

Question 5

(b) What is cookie? Explain the setcookie() function in PHP with meaning of all the arguments.

bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] )
nameThe name of the cookie.
value The value of the cookie. This value is stored on the clients computer
expireThe time the cookie expires.you'll most likely set this with the time() function plus the number of seconds before you want it to expire.
pathThe path on the server in which the cookie will be available on.
domainThe domain that the cookie is available to. 
secureIndicates that the cookie should only be transmitted over a secure HTTPS connection from the client. When set to TRUE, the cookie will only be set if a secure connection exists.
httponlyWhen TRUE the cookie will be made accessible only through the HTTP protocol. This means that the cookie won't be accessible by scripting languages, such as JavaScript. 

Web Technology and Programming - Nov 2011

Question 3

(b) Write a program using Java Script, which sorts elements of an array in descending order using bubble sort.
<html>
<head>
<script type="text/javascript">
var array = new Array(15,23,1,69,45,36,7,64,99,5);
document.write("Array is "+ array);
var arrayLength = array.length;
var i;
var j;
var k;
for(i=0;i<arrayLength;i++)
{
 for(j=i+1;j<arrayLength;j++)
 {
   if(array[i]<array[j])
   {
             k=array[i];
    array[i]=array[j];
    array[j]=k;
   }
    }
}
document.write("<br/>After bubble sort in desending order " + array);
</script>
</head>
<body>
</body>
</html>

    
(b) Create a HTML page with Java Script, which takes one integer number as input and tells whether the number is even or odd.
<html>
<body>
<script type="text/javascript">
function checkDigit(e)
{
var keynum;
var keychar;
var numcheck;
 if(window.event) 
  keynum = e.keyCode;
 else if(e.which) 
  keynum = e.which;
 if(keynum != 8)
 {
  keychar = String.fromCharCode(keynum);
  numcheck = /\d/;
  return numcheck.test(keychar);
 }
 else
  return keynum;
}
function display()
{
var x = document.getElementById('txt1').value;
if(x%2 == 0)
alert("Even Numbers");
else
alert("Odd Numbers");
}
</script>
<form>
Type numbers : 
<input type="text" onKeyDown="return checkDigit(event)"  id="txt1"/>
<button onClick="display()">Click Me</button>
</form>
</body>
</html>
 

Question 4

(b) Create a HTML page using Java Script, which gives functionality of calculator like addition, multiplication, division and subtraction.
<html>
<head>
<script type="text/javascript">
function result(x)
{
var x1 =  document.getElementById('txt1').value;
var y1 =  document.getElementById('txt2').value;
if(x == "add")
document.getElementById('result').value = parseInt(x1) + parseInt(y1);
else if(x == "sub")
document.getElementById('result').value = parseInt(x1) - parseInt(y1);
else if(x == "mul")
document.getElementById('result').value = parseInt(x1) * parseInt(y1);
else if(x == "div")
document.getElementById('result').value = parseInt(x1) / parseInt(y1);
}
</script>
</head>
<body>
<input type="text" name="txt1"  id="txt1" value="0" placeholder="Number 1"/>
<input type="text" name="txt2"  id="txt2" value="0" placeholder="Number 2"/>
<br/>
Result is :
<input type="text" name="result"  id="result" placeholder="Result"/>
<br/>
<button value="add" onClick="result(this.value)">Addition</button>
<button value="sub" onClick="result(this.value)">Subtraction</button>
<button value="mul" onClick="result(this.value)">Multiplication</button>
<button value="div" onClick="result(this.value)">Division</button>
</body>
</html>

Question 5

(b) Explain the PHP session and PHP cookie with an example.
<?php
session_start();
session_register('counter');
$_SESSION['counter']= $_SESSION['counter'] + 1;
if ($_SESSION['counter']==1)
{
echo "<h1><center>Welcome! You are a first-time visitor
</center></h1>";
}
else
{
echo "<h1><center>
You have visited this page". $_SESSION['counter'] ."times.Thanks for your visit!</center></h1>";
}
?> <?php setcookie("Username", "Help2Engg");
echo $_COOKIE["Username"];
?>
 

Web Technology and Programming - May 2011

Question 1

(b) What is HTML table? Explain table element with necessary attributes. Give the code to print following table.


<table border="1">
  <tr>
    <td height="50px" width="300px" colspan="3"></td>
  </tr>
  <tr>
    <td height="100px" width="100px"></td>
    <td colspan="2" width="200px" height="100px"><table border="1">
        <tr>
          <td width="100px" height="50px"></td>
          <td width="100px" height="50px"></td>
        </tr>
        <tr>
          <td width="100px" height="50px"></td>
          <td width="100px" height="50px"></td>
        </tr>
      </table></td>
    </td>
  </tr>
  <tr>
   <td height="50px" width="50px"></td>
    <td height="50px" width="50px"></td>
     <td height="50px" width="50px"></td>
  </tr>
</table> 
 

Question 2

(b) What is frame set? Explain the use of frame set in web site design with proper example.
index.html
<html>
<frameset cols="20%,80%">
<frame name="main" src="1.html">
<frameset cols="25%,75%">
<frame name="f1" src="1-1.html" />
<frame name="f2" src="1-2.html" />
</frameset>
</frameset><noframes></noframes>
</html>
 
1.html
<html>
<body>
First Frame<br/>
<a href="1-1.html" target="f2">Second Frame</a>
<br/>
<a href="1-2.html" target="f1">Third Frame</a>
<br/>
</body>
</html>

1-1.html
<html>
<body>
Third Frame
</body>
</html>
 
1-2.html
<html>
<body>
Second frame
</body>
</html>

Question 3

(a) What do you mean by event in JavaScript? Give at least two examples of events with their handling.

  <html>
<head>
<script type="text/javascript">
function bgset()
{
 document.getElementById('txt1').style.backgroundColor = "Yellow";
 }
 function bgsetb()
{
 document.getElementById('btn1').style.backgroundColor = "red";
 }
</script>
</head>
<body>
<form>
  <input type="text" onFocus="bgset()" id="txt1" />
</form>
<button id="btn1" onClick="bgsetb()">Click Me</button>
</body>
</html>

  
(b) Write a JavaScript program to print first N odd numbers divisible by 7.

<html>
<body>
<script type="text/javascript">
function display()
{
 var x = document.getElementById('txt1').value;
 var i = 0;
 for(i=0;i<=x;i++)
 {
  if(i%2 != 0)
  {
   if(i%7 == 0)
   {
    document.write("<br/>");
    document.write(i);
    }
   }
  }
 }
</script>
</body>
<input type="text" id="txt1" />
<button onClick="display()">Display</button>
</html>

(b) Write an HTML form accepting an integer having 4-digits. Provide necessary validations using JavaScript. Input should not accept characters.

<html>
<body>
<script type="text/javascript">
function noNumbers(e)
{
var keynum;
var keychar;
var numcheck;
 if(window.event) 
 {
  keynum = e.keyCode;
 }
 else if(e.which) 
 {
  keynum = e.which;
 }
 if(keynum != 8)
 {
  keychar = String.fromCharCode(keynum);
  numcheck = /\d/;
  return numcheck.test(keychar);
 }
 else
 return keynum;
}
</script>
<form>
Type only numbers : 
<input type="text" onKeyDown="return checkDigit(event)" />
</form>
</body>
</html>

Question 4

(b) Write a PHP program to make the sum of first 100 odd numbers.

<html>

  <body>

            <?php

            $sum = 0;

            $counter = 0;

         for($i = 0;$counter < 100;$i++)

          {

            if($i%2 != 0)

            {
                $sum += $i;

                $counter++;
                        }
                  }
echo $sum;
?>
</body>
</html>

Question 5

(a) Write PERL programs for
1. Printing first N odd numbers


#!/perl/bin/perl -w
$counter = 0;
for($i=0;$counter<100;$i++)
{
 if($i%2 != 0)
 {
  print "$i ";
  $counter++;
 }
}
  
2. Reverse an integer number
#!/perl/bin/perl -w
$number = 123;
$sum = 0;
$temp = 0;
while($number>0)
{
 $temp = $number%10;
 $sum += $sum*10 + $temp;
 $number = $number / 10;
}