PDF for IT Practical(JS & PHP)
PDF for IT Practical(JS & PHP)
Program:-
<!DOCTYPE html>
<html><head>
<title>Background color</title>
</head>
<body>
<form name="f1">
</form></body>
<script type="text/javascript">
function red()
window.document.bgColor="red";
window.setTimeout("green()",1000);
function green()
window.document.bgColor="green";
window.setTimeout("orange()",1000);
function orange()
{
window.document.bgColor="orange";
window.setTimeout("yellow()",1000);
function yellow()
window.document.bgColor="yellow";
window.setTimeout("purple()",1000);
function purple()
window.document.bgColor="purple";
window.setTimeout("grey()",1000);
function grey()
window.document.bgColor="grey";
window.setTimeout("aqua()",1000);
function aqua()
window.document.bgColor="aqua";
function msg()
</script></html>
Program:-
<!DOCTYPE html>
<html><head><title>Background color</title></head>
</body>
<script type="text/javascript">
function yellow()
window.document.bgColor="yellow";
window.setTimeout("orange()",1000);
function orange()
window.document.bgColor="orange";
window.setTimeout("green()",1000);
function green()
window.document.bgColor="green";
window.setTimeout("red()",1000);
}
function red()
window.document.bgColor="red";
window.setTimeout("blue()", 1000);
function blue()
window.document.bgColor="blue";
window.setTimeout("aqua()" ,1000);
function aqua()
window.document.bgColor="aqua";
window.setTimeout("black()" ,1000);
function black()
{window.document.bgColor="black";
function msg()
alert("Display of 7 colors");
</script></html>
Javascript SOP 2:- Create event driven Javascript program for the following. Make use of appropriate
variables, Javascript inbuilt string functions and control structures.
➢ To accept string from user and count number of vowels in the given string.
Program:-
<!DOCTYPE html>
<html>
<head>
<title>
String function</title>
</head>
<body>
<form name="form1">
</form>
</body>
<script type="text/Javascript">
function cnt()
var s,i,ch,c;
c=0;
s=form1.t1.value;
for(i=0;i<=s.length;i++)
{
ch=s.charAt(i);
if(ch=="A"|| ch=="a"||ch=="E"||ch=="e"||ch=="I"||ch=="i"||ch=="O"||ch=="o"||ch=="U"||ch=="u")
c++;
</script>
</html>
Javascript SOP 3:- Create event driven Javascript program for the following. Make use of appropriate
variables, Javascript inbuilt string functions and control structures.
➢ To accept string from user and reverse the given string and check whether it is palindrome or
not.
program:-
<!DOCTYPE html>
<html>
<Head><title>Palindrome</title></Head>
<Body>
<form name="frm1">
</form>
</Body>
<script >
function chk()
var a,s,i,ch,n;
a=frm1.t1.value;
s=a.toLowerCase();
n=s.length;
var p=1;
for(i=0;i<n/2;i++)
{
if(s.charAt(i)!=s.charAt(n-1-i))
p=0;
break;
if(p==1)
alert("string is Palindrome");
else
</script>
</html>
Javascript SOP 4:- Create event driven Javascript program to convert temperature to and from Celsius,
Fahrenheit.
Formula:- c/5=(f-32)/9
Program:-
<!DOCTYPE html>
<html><head>
<script type="text/javascript">
function get_Fahrenheit()
var c = parseInt(document.getElementById('c1').value);
var f;
f = c/5*(9)+32;
document.write("Fahrenheit : "+f);
function get_Celsius()
var f = parseInt(document.getElementById('f1').value);
var c;
c = ((f-32)/9)*5;
document.write("Celsius : "+c);
}
</script>
</head>
<body bgcolor=”lime”>
<h1>Temperature Conversion</h1>
</body></html>
PHP Programming:-
1. If statement in PHP : if statement allows programmer to make decision, based on one or more
conditions; and execute a piece of code conditionally.
Syntax : if(condition)
block of statement;
2. If-else statement in PHP : if-else statement allows programmer to make decision based on either this
or that conditions.
Syntax : if(condition)
Statement;
else
Statement;
Program :
<?php
$marks=80;
if($marks> =60)
else {
?>
Output :
Loops are used to execute the same block of code repeatedly as long as a certain condition is satisfied.
For eg : 'For loop' in PHP
Syntax :
for(initialisation;condition;incrementation or decrementation)
{ Statement;
Program :
<?php
for($i=1;$i <=5;$i++)
?>
code to be executed;
Function Description
strlen() Returns the length of a string (i.e. total no. of characters)
strpos() Searches for a specific text within a string and returns the character position of
the first match and if no match is found, then it will return false
trim() Removes whitespace and other predefined characters from both sides of a string
A string is series of characters. The real power of PHP comes from its functions. A function is a block of
statements that can be used repeatedly in a program. PHP has many built-in functions that can be called
directly to perform a specific task.
3. Server Side Scripting - PHP
SOP 1. Write a PHP program to check if a person is eligible to vote or not. The Program should include
the following-
Program:-
<!DOCTYPE html>
<html>
<body>
</form>
</body>
</html>
<?php
if (isset($_POST['submit']))
$age = $_POST['t1'];
if($age>=18)
} ?>
SOP 2. Write a PHP function to count the total number of vowels (a,e,i,o,u) from the string. Accept a
string by using HTML form.
Program:-
<html>
<body>
Enter String
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
$str = strtolower($_POST['str']);
$vowels=array('a','e','i','o','u');
$len=strlen($str);
$num=0;
for($i=0;$i<$len;$i++)
{
if(in_array($str[$i],$vowels))
$num++;
echo"Number of vowels:.$num";
?>
SOP 3. Write a PHP program to save marks of English, Hindi, Marathi, Maths, and Information
Technology in an array. Display marks of individual subject along with total marks and percentage.
Program:-
<?php
$a=array(60,78,74,85,96);
$t=0;
$x=0;
$c=count($a);
for($x=0;$x<$c;$x++)
echo"<br><br>Marks in subject.$a[$x]";
$t=$t+$a[$x];
$p=$t*100/500;
?>