Javascript SOP 1 Part 1:-
Program:-
<!DOCTYPE html>
<html><head>
<title>Background color</title>
</head>
<body>
<H1>7 Different & visibly distinct background colors</H1>
<form name="f1">
<input type="button" value="Change Color" onMouseOver="red()">
<input type="button" value="Your Status" onClick="msg()">
</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()
window.status="The program is properly working";
}
</script></html>
Javascript SOP 1 Part 2:-
Program:-
<!DOCTYPE html>
<html><head><title>Background color</title></head>
<body onload="yellow()" onunload="msg()">
<h1 align="center">7 Different & visibly distinct background colors</h1>
</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">
Enter your name
<input type="text" name="t1"><br>
<input type="button" name="btncheck" value="count Vowels"onClick="cnt()">
</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++;
alert("Number of vowels in string are"+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">
Enter your name
<input type="text" name="t1"><br><br><br>
<input type="Button" name="btncheck" value="Check palindrome" OnClick="chk()">
</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
alert("String is not a palindrome");
</script>
</html>
Javascript SOP 4:- Create event driven Javascript program to convert temperature to and from Celsius,
Fahrenheit.
Formula:- c/5=(f-32)/9
[where c=Temperature in Celsius and f=Temperature in Fahrenheit.]
Output format: 40 Celsius= 104 Fahrenheit
45 Fahrenheit= 7.22222222 Celsius.
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>
<input type="text" id="c1" placeholder="Temperature in Celsius">
<input type="submit" onclick="get_Fahrenheit()"><br>
<input type="number" id="f1" placeholder="Temperature in Fahrenheit">
<input type="submit" onclick="get_Celsius()">
</body></html>
PHP Programming:-
Control structures in PHP :
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)
echo"you passed with first class";
}
else {
echo"you can do better";
?>
Output :
you passed with first class
3. Loop Structure in PHP :
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++)
echo"The number is".$i."<br>"; }
?>
Output : The number is: 1
The number is: 2
The number is: 3
The number is: 4
The number is: 5
Use of foreach loop : This loop works only on arrays, and is used to loop through each key/value pair in
an array.
Syntax : foreach ($array as $value)
code to be executed;
❖ Following are the few predefined functions in PHP to manipulate string.
Function Description
strlen() Returns the length of a string (i.e. total no. of characters)
str_word_count() Counts the number of words in a string
strrev() Reverses a string
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
str_replace() Replaces some characters with some other characters in a string
substr() Returns a part of a string
strtolower() Converts a string to lowercase
substr_count() Counts the number of times a substring occurs in a string
ucwords() Converts the first character of each word in a string to uppercase
trim() Removes whitespace and other predefined characters from both sides of a string
Example : The program below shows few string manipulation functions.
PHP String Functions:-
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-
➢ Minimum age required for vote is 18.
➢ Use PHP function
➢ Use Decision making statement.
Program:-
<!DOCTYPE html>
<html>
<body>
<h1 align="center">Person eligible to vote or not</h1>
<form action="age.php" method="post">
<h2>Enter age : </h2>
<input type="text" name="t1"><br><br>
<input type="submit" name="submit" value="submit"></h2>
</form>
</body>
</html>
<?php
if (isset($_POST['submit']))
$age = $_POST['t1'];
if($age>=18)
echo "<h2>You are Eligible to Vote</h2>";
else
echo "<h2>You are not Eligible to Vote</h2>";
} ?>
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>
<h1 align="center">String Function</h1>
<form method="post" action="vowel.php">
Enter String
<input type="text" name="str"><br><br>
<input type="submit" name="submit" value="Count vowels">
</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;
echo"<br><br>Total is: .$t";
echo"<br><br>Percentage is: .$p";
?>