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"];
?>
No comments:
Post a Comment