Programming

Change Your Page Background Color Dynamically using Java Script

Following code is used to change a page color from your select option in select box.

Copy and Paste following code in a simple HTML page.

[html]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Change Your page Background Color Using Java Script</title>
<script type="text/javascript">
function changeTheme(selColor) {
alert(selColor);
document.body.style.backgroundColor = selColor;
}
</script>

</head>
<body>
<h1>Please Select Your Page Background Color..</h1>
<select name="changescheme" id="changescheme" onChange="javascript:changeTheme(this.value)">
<option value="white">White</option>
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="orange">Orange</option>
<option value="black">Black</option>
</select>
</body>
</html>
[/html]

Tags: , ,

Giving Links In CSS

/* The Example1 will be having the font styles,colors and  font size for the content present in Example2. copy and paste the code of Example2 to get the output.*/

Example1.css

[css]
body
{
background-color:yellow;
}
h1
{
font-size:36pt;
}
h2
{
color:blue;
}
p
{
margin-left:50px;
}
[/css]

Example2.css

[css]
<html>
<head>
<link rel="stylesheet" type="text/css"  href="example1.css"  />
</head>
<body>
<h1>Hai!!</h1>
<h2>Have A Nice Day</h2>
</body>
</html>
[/css]

Output:

Hai!!

Have A Nice Day

Tags:

JavaScript To Find Greatest Among 3 Numbers

/* The Following Script will display the greatest among three numbers*/

[html]
<html>
<head>
<h1>Greatest Among Three Numbers</h1>
</head>
<body>
<script type="text/javascript">
var a=10,b=20,c=7;

/* checks a>b and a>c  if  both conditions satisfied, A is greater */

if (a>b  && a>c)
{
document.write("<b>A is greater</b>");
}

/* checks b>a  and b>c  if  both conditions satisfied, b is greater */

if (b>a  && b>c)
{
document.write("<b>B is greater</b>");
}

/* if the above two conditions were false c is greater*/

else
{
document.write("<b>C is greater</b>");
}
</script>
</body>
</html>
[/html]

The Output will be:

Greatest Among  Three Numbers

B is Greater


javascript-displays the alert message

Create new html file and copy the code and save it as popup.html.

popup.html

[html]
<strong> </strong><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
function popup()
{
alert("Good morning");
}
</script>
</head>

<body>
<input type="button" onClick="popup()" value="clickhere" />
</body>
</html>
[/html]

It displays the output clickhere button which displays the alert message as “Good morning”

Tags:

A Simple javascript

[js]
<script type="text/javascript">
<!–
document.write("WELCOME");
–>
</script>
[/js]

It display the output as:

WELCOME

Tags:

To display the current day and image for a particular day

[php]
<?php
$today=date(l);
if($today==Monday)
{
echo "Today is Monday" ."<br/>";
echo "<img src=’images/image1.gif’>";
}
elseif($today==Tuesday)
{
echo "Today is Tussday" ."<br/>";
echo "<img src=’images/image2.gif’>";
}
elseif($today==Wedsday)
{
echo "Today is Wedsday" ."<br/>";
echo "<img src=’images/image3.gif’>";
}
elseif($today==Thursday)
{
echo "Today is Thursday" ."<br/>";
echo "<img src=’images/image4.gif’>";
}

elseif($today==Friday){
echo "Today is Friday"."<br/>";
echo "<img src=’images/image5.gif’>";
}

elseif($today==Saturday){
echo "Today is Saturday"."<br/>";
echo "<img src=’images/image6.gif’>";
}

elseif($today==Sunday){
echo "Today is Sunday"."<br/>";
echo "<img src=’images/image7.gif’>";
}
?>
[/php]

//create the folder name as images and store the 7 images. So, it will display the todays image.

It display the output as:

Today is Friday

Tags:

To display current date,no.of days and weeks in a month and year using php

1:Create new php file and copy the code and save it as file1.php.

2.Run file1.php, then it will display the current date and no.of days,weeks in a month and year.

[php]
<?php
echo  "My name is: John"."<br/>";
echo "current date is:"."\n" .date("Y m d h: s: m") ."<br/>";
echo "No of days in a month:"."\n" .cal_days_in_month( CAL_GREGORIAN, 07, 2010) ."<br/>";
echo "No of weeks in a month:"."\n".date("w", mktime(0,0,0,12,31,2010)) ."<br/>";
echo "No of weeks in a year:"."\n" .date("W", mktime(0,0,0,12,31,2010)) ."<br/>";
?>
[/php]

It display the output as:

My name is: John
current date is: 2010 07 23 04: 46: 07
No of days in a month: 31
No of weeks in a month: 5
No of weeks in a year: 52

Tags:

Javascript to wish “Good Morning”

WISHES FOR A DAY

/* This script will display A “Good Morning” Message if the time is less than or equal to 10.Otherwise, it display a “Message Good Day”*/

[js]
<html>
<body>
<script type="text/javascript">
var d = new Date();
var time = d.getHours();
if (time <= 10)
{
document.write("<h1>Hai Good morning!!!</h1>");
}
else
{
document.write("</h1>Good day!!!!!!!</h1>");
}
</script>
</body>
</html>
[/js]

It produces the output as :

if the time is <=10

Hai!!!!Good morning

otherwise

Good day!!!!!!!

Javascript to display date and time

/*This script is used to display  the current date and time*/

[js]
<html>
<body>
<script type="text/javascript">
var date=new Date();
document.write(date);
</script>
</body>
</html>
[/js]

The output will be in the following format:Wed Jul 21 2010 15:14:05 GMT+0530 (India Standard Time)

A simple CSS code

/* A Simple CSS code to display A  Message*/

[css]
<html>
<head>
<style type="text/css" >
body
{
background-color:blue;
}
h1
{
color:blue;
text-align:center;
}
p
{
font-family:"times new roman";
font-size=20px;
}
</style>
</head>
<body>
<h1> CSS WELCOME!!!</h1>
<p>Hi!!!Welcome To CSS.</p>
</body>
</html>
[/css]

The output will be like this

Hi!!!Welcome To CSS.

Request a Free SEO Quote