Web Tech
Web Tech
HTML Elements
PROGRAM OUTPUT
HTML Links
<html>
<body> This is a link
<a href="http://www.saif4u.webs.com">
This is a link</a>
</body>
</html>
31
HTML Frames:
Program Output
HTML <Horizontal frameset>Tag
<html>
<frameset rows="25%,50%,25%">
<frame src="frame_a.htm"/>
<frame src="frame_b.htm"/>
<frame src="frame_c.htm"/>
</frameset>
</html>
HTML <noframes>Tag
<html>
<frameset cols="25%,50%,25%">
<frame src="frame_a.htm"/>
<frame src="frame_b.htm"/>
<frame src="frame_c.htm"/>
<noframes>
Sorry, your browser does not handle
frames!
</noframes>
</frameset>
</html>
HTML Forms:
Program Output
TEXT FIELD First name:
<html>
<body> Last name:
<form action="">
First name: <input type="text" Note: The form itself is not visible. Also
name="firstname" /><br /> note that the default width of a text field is
Last name: <input type="text" 20 characters.
name="lastname" />
</form>
<p><b>Note:</b> The form itself is not
visible. Also note that the default width of a
text field is 20 characters.</p>
</body>
</html>
PASSWORD FIELD
<html>
Username:
<body>
<form action=""> Password:
Username: <input type="text" name="user"
/><br /> Note: The characters in a password field are
Password: <input type="password" masked (shown as asterisks or circles).
name="password" />
</form>
<p><b>Note:</b> The characters in a
password field are masked (shown as
asterisks or circles).</p>
</body>
</html>
CHECKBOXES
<html>
I have a bike
<body>
<form action=""> I have a car
<input type="checkbox" name="vehicle"
value="Bike" /> I have a bike<br />
<input type="checkbox" name="vehicle"
value="Car" /> I have a car
</form>
</body>
</html>
RADIO BUTTONS
<html>
Male
<body>
<form action=""> Female
43
Create a Button
<html>
<body>
<form action="">
<input type="button" value="Hello
world!">
</form>
</body>
</html>
Draw a border around form-data
<html>
<body>
<form action="">
<fieldset>
<legend>Personal information:</legend>
Name: <input type="text" size="30" /><br
/>
E-mail: <input type="text" size="30" /><br
/>
Date of birth: <input type="text" size="10"
/>
</fieldset>
</form>
</body>
</html>
45
Changing text:
PROGRAM OUTPUT
<html>
<body>
<h1 id="header">Old Header</h1> NewHeader
<script
type="text/javascript">document.getElementById("he "Old Header" was changed to
ader").innerHTML="N ew Header"; "NewHeader"
</script>
<p>"Old Header" was changed to "New Header"</p>
</body>
</html>
<html> Mouse over this text!
<head>
<script type="text/javascript">
function nameon() How are you today?
{
document.getElementById('h2text').innerHTML="WE
LCOME!";
WELCOME!
}
function nameout() (Click on text to change text)
{
12
document.getElementById('h2text').innerHTML="Ho
w are you today?";
}
</script>
</head>
<body>
<h2 id="h2text" onmouseout="nameout()"
onmouseover="nameon()">
Mouse over this text!</h2>
</body>
</html>
<html>
<head>
<script type="text/javascript"> Blinking header
function blinking_header()
{
if (!document.getElementById('blink').style.color) Blinking header
{
document.getElementById('blink').style.color= (Click on text to blink text in
"red"; red color)
}
if
(document.getElementById('blink').style.color=="red"
)
{
document.getElementById('blink').style.color=
"black";
}
else
{
document.getElementById('blink').style.color=
"red";
}
timer=setTimeout("blinking_header()",100);
}
function stoptimer()
{
clearTimeout(timer);
}
</script>
</head>
<body onload="blinking_header()"
onunload="stoptimer()">
<h1 id="blink">Blinking header</h1>
</body>
</html>
13
PROGRAM OUTPUT
<html> When you mouse over the
<head> image, a new image will
<script type="text/javascript"> appear.
img2=new Image();
img2.src="landscape3.gif";
function changeImage()
{
document.getElementById('myImage').src=img2.src;
}
</script>
</head>
<body> The new image appears
<p>When you mouse over the image, a new image instantly, because your browser
will appear.</p> has already loaded the image
<img id="myImage" onmouseover="changeImage()"
border="0" width="160" height="120"
src="landscape2.jpg">
<p>The new image appears instantly, because your
browser has already loaded the image.</p>
</body>
</html>
<html>
<head>
<script type="text/javascript"> Move the cursor over this
function cursor(event) page
{
document.getElementById('trail').style.visibility="visible" (Move your cursor on output
; window to show cursor text)
document.getElementById('trail').style.position="absolute
";
document.getElementById('trail').style.left=event.clientX
+10;
document.getElementById('trail').style.top=event.clientY;
}
</script>
</head>
<body onmousemove="cursor(event)">
<h1>Move the cursor over this page</h1>
<span id="trail" style="visibility:hidden">Cursor
Text</span>
</body>
</html>
14
Result
Click Me
<!doctype html>
<html>
<head>
<script>
function odd_even(){
var no;
no=Number(document.getElementById("no_input").value);
if(no%2==0)
{
alert("Even Number");
}
else
{
alert("Odd Number");
}
}
</script>
</head>
<body>
Enter Any Number:<input id="no_input"><br />
<button onclick="odd_even()">Click me</button>
</body>
</html>
Result
Enter Any Number:
Click Me
3) Factorial prgram
<!doctype html>
<html>
<head>
<script>
function show(){
<html>
<head>
<script>
function add(){
var a,b,c;
a=Number(document.getElementById("first").value);
b=Number(document.getElementById("second").value);
c= a + b;
document.getElementById("answer").value= c;
}
</script>
</head>
<body>
<input id="first">
<input id="second">
<button onclick="add()">Add</button>
<input id="answer">
</body>
</html>
Result
Enter First Number:
Enter Second Number:
Add
<html>
<head>
<script type="text/javascript">
var a;
var n=prompt("Enter a number for the no. of rows in a pattern");
for(var i=1;i<=n;i++)
{
for(var j=1;j<=i;j++)
{
document.write("0"+j+" ");
}
document.write("<br />");
}
</script>
</head>
<body>
</body>
</html>
Output
01
01 02
01 02 03
01 02 03 04
01 02 03 04 05
<!doctype html>
<html>
<head>
<script>
function palin()
{
var a,no,b,temp=0;
no=Number(document.getElementById("no_input").value);
b=no;
while(no>0)
{
a=no%10;
no=parseInt(no/10);
temp=temp*10+a;
}
alert(temp);
}
</script>
</head>
<body>
Enter any Number: <input id="no_input">
<button onclick="palin()">Check</button></br></br>
</body>
</html>
Result
Enter any Number: Check
Print Triangle of Stars in JavaScript
<html>
<head>
<script type="text/javascript">
var i, j;
//outer loop
for(i=1; i <= 5; i++)
{
//inner loop
for(j=1; j<=i; j++)
{
document.write('*');
}
document.write('<br/>');
}
</script>
</head>
<body>
</body>
</html>
Output
*
**
***
****
*****
Print Triangle of Stars in JavaScript
<html>
<head>
<script type="text/javascript">
var i, j;
//outer loop
for(i=5;i>=1;i--)
{
//inner loop
for(j=1;j<=i;j++)
{
document.write('*');
}
document.write('<br/>');
}
</script>
</head>
<body>
</body>
</html>
Output
*****
****
***
**
*