You are on page 1of 50

Alert Box Demo:

CODE:

<HTML>
<HEAD>
<SCRIPT TYPE="TEXT/JavaScript">
function MsgBox (textstring)
{
document.write('<p style="background-color:BLACK;font-
size:46;text-align:center;color:CYAN">');
document.write("im alerting text string u enterd!!" +textstring );
document.write('</p>');
var x=alert (textstring) ;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT NAME="text1" TYPE=Text>
<INPUT NAME="submit" TYPE=Button VALUE="Show Me"
onClick="MsgBox(form.text1.value)">
</FORM>
</BODY>
</HTML>
OUTPUT:
Arrays Demo using Onload():
CODE:
<html>
<head>
</head>
<script type="text/javascript">
<!--
function onloaddemo() {
var a1 = new Array(67,8,9);
document.write('<body style="background-
color:BLACK;color:CYAN;text-align:center;font-
size:45">');

for(var i=0; i < a1.length; i++) {


document.write("value of a[" +(i)+"]element of
array:"+a1[i]);
document.write('</br>');
}
document.write('</body>');
}
//-->
</script>
<body onLoad="onloaddemo()">

</body>
</html>
OUTPUT:
OnChange Demo:

CODE:
<html>
<head>
</head>
<script type="text/javascript">
<!--
function onchangedemo()
{
alert("u have changed");
}
//-->
</script>
<form>

<input type="text" value="here"


onChange="onchangedemo()"/>

</form>
</html>
OUTPUT:
onMouseOver demo:

CODE:

<html>
<head>
</head>
<script type="text/javascript">
<!--
function moverdemo() {
alert("u r on the text");
}

//-->
</script>
<body>
<p onMouseOver="moverdemo()">u r in html page</p>
<p> hello world</p>
</body>
</html>
OUTPUT:
Functions Demo:
CODE:
<html>
<head>
<script type="text/javascript">
function display()
{
document.write('<body style=background-color:CYAN><p
style="color:BLACK;text-align:center;font-size:50" >Helloo
world!! im inside a function in the Script!</pre>');
}

</script>
</head>
<body>
<script type="text/javascript">
display();
</script>
</body>

OUTPUT:
Printing stars Demo:
CODE:
<HTML>
<HEAD>
<TITLE>
PROMPT DEMO
</TITLE>
</HEAD>
<BODY style=background-color:BLACK>
<SCRIPT language="JavaScript">
<!-- Beginning of JavaScript -
function demoprompt()
{
var x=prompt("GIVE VALUE FOR X"," ");
document.write('<body style=background-color:BLACK>');
document.write('<pre style="color:CYAN;font-size:60" >');
for(i=1;i<=x;i++)
{
document.write("*");
}
document.write('</pre>');
document.write('</body>');
}
</SCRIPT>
<form align="center">
<input type="button" onclick="demoprompt()" value="Show
prompt box" />
</form>
</BODY>
</HTML>
Object Demo :
CODE:
<html>
<body>
<script LANGUAGE="javascript">

var person={fname:"John",lname:"Doe",age:25};
document.write('<p style="text-align:center;background-
color:BLACK;color:CYAN;font-size:50">')
document.write(" First Name Last name Age \n");
document.write('</p>')
for (x in person)
{
document.write('<body style="text-align:center;background-
color:CYAN;color:RED;font-size:50">')
document.write(person[x] + " ");
document.write('</body>')
}
</script>

</body>
OUTPUT:
Expression evaluation Demo:
CODE:
<html>
<head>
</head>
<body>
<script type="text/javascript">
function evaldemo(textstr)
{

var str2=eval(textstr);
document.f1.t2.value=str2;
}
</script>
<form name="f1">
Expression:<input type="text" name=t1 />
</br>
<input type="button" value="submit"
onclick=evaldemo(form.t1.value) />
</br>
Result:<input type="text" name=t2 />
</br>
</form>
</body>
</html>
OUTPUT:
Email Id validation Demo:
CODE:
<html>
<head>
<script type="text/javascript">
function val()
{
var x=document.f1.t1.value;
if (x==null || x=="")
{
alert("First name must be filled out");
}
var y=document.f1.t2.value;
var atpos=y.indexOf("@");
var dotpos=y.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
alert("Not a valid e-mail address");
}
var p=document.f1.p1.value;
var pc=document.f1.p2.value;
if(p!=pc)
{
alert("password confirmation failed");
}
}
</script>
</head>
<body style="background-color:pink">
<form name="f1" align:right>
FIRST NAME :<input type="text" name="t1"/><br/>
EMAIL-ID:<input type="text" name="t2"/><br/>
PASSWORD:<input type="password" name="p1"/><br/>
CONFIRM PASSWORD:<input type="password"
name="p2"/><br/>
<input type="button" value="submit" onclick="val()"/>
<input type="reset" value="reset" />
</form>
</body>
</html>
OUTPUT:
HTML DOM Examples:

Accessing HTML content Demo:


CODE:
<html>
<head><title>Dom Examples</title>
</head>
<body style="color:blue ;font-size:20pt;">
<h id="p1">javascript--- client side script
</h>
<p id="p2">document object model----API for accessing
html content</p>
<script type="text/javascript">
var pnode=document.getElementById("p1");
var p2node=document.getElementById("p2");
var ptext=p2node.innerHTML;
document.write("type of the node h:
"+pnode.nodeType+"<br/>");
document.write("type of the node heading tag:
"+pnode.nodeName+"<br/>");
document.write("child nodes of tag:
"+pnode.childNodes[0].nodeValue+"<br/>");
document.write("first child of tag:
"+pnode.firstChild.nodeValue+"<br/>");
document.write("content of p tag: "+ptext);
</script>
</body>
</html>
OUTPUT:
Accessing Element By Tag demo:
CODE:
<html>
<head><title>acessing element by tag</title></head>
<body style=" color:purple ; font-size:18pt;">
<h>im the content with h tag</h>
<p>im the 0th p tag content</p>
<p>im the 1st p tag content</p>
<p>im the 2nd p tag content</p>
<p id ="p1"> im the text with id name p1</p>
<script type="text/javascript">
var usetag1=document.getElementsByTagName("h");
var usetag2=document.getElementsByTagName("p");
var usetag3=document.getElementsByTagName("p1");
document.write("tag h content:
"+usetag1[0].innerHTML+"</br>");
document.write("0th tag p content:
"+usetag2[0].innerHTML+"</br>");
document.write("1st tag p content :
"+usetag2[1].innerHTML+"</br>");
document.write("2nd tag p content :
"+usetag2[2].innerHTML+"</br>");
document.write("3rd tag p content:
"+usetag2[3].innerHTML+"</br>");
document.write(" p tag with id p1:
"+usetag3[0].innerHTML+"</br>");

</script>
</body>
OUTPUT:
Creating Tags demo:
CODE:
<html>
<body id="b1" style="color:red;font-size:20">
<script type="text/javascript">
// create a new paragraph
newpara = document.createElement("p");
newh=document.createElement("h");
// now some text
sometext = document.createTextNode("content to b attached
to p tag");
text=document.createTextNode("content to beattached to h
tag");
newpara.appendChild(sometext);
newh.appendChild(text);
// stick the paragraph onto an existing object
obj1 = document.getElementById("b1");
obj1.appendChild(newpara);
obj1.appendChild(newh);
</script>
</body>
</html>
OUTPUT:
XML examples:

User Information Demo Using XSLT:


CODE:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="userinfm.xsl"?>
<information>
<user>
<name>user1</name>
<branch>cse</branch>
<id>1</id>
<email>abc@gmail.com</email>
</user>

<user>
<name>user2</name>
<branch>eee</branch>
<id>2</id>
<email>xyz@gmail.com</email>
</user>

<user>
<name>user3</name>
<branch>ece</branch>
<id>3</id>
<email>lmn@gmail.com</email>
</user>
<user>
<name>user4</name>
<branch>mech</branch>
<id>4</id>
<email>pqr@gmail.com</email>
</user>

<user>
<name>user5</name>
<branch>prod</branch>
<id>5</id>
<email>z@gmail.com</email>
</user>

<user>
<name>user6</name>
<branch>mca</branch>
<id>6</id>
<email>pqr@gmail.com</email>
</user>

<user>
<name>user7</name>
<branch>chem</branch>
<id>7</id>
<email>qr@gmail.com</email>
</user>

<user>
<name>user8</name>
<branch>biotec</branch>
<id>8</id>
<email>pr@gmail.com</email>
</user>

<user>
<name>user9</name>
<branch>it</branch>
<id>9</id>
<email>r@gmail.com</email>
</user>

<user>
<name>user10</name>
<branch>robotics</branch>
<id>10</id>
<email>m@gmail.com</email>
</user>
</information>

XSLT style sheet:


CODE:
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<html>
<body>
<h2>User Information</h2>
<table border="1">
<tr>
<th align="center">NAME</th>
<th align="center">BRANCH</th>
<th align="center">IDENTITYNO</th>
<th align="center">EMAIL</th>
</tr>

<xsl:for-each select="information/user">
<tr>
<td align="center"><xsl:value-of
select="name"/></td>
<td align="center"><xsl:value-of
select="branch"/></td>
<td align="center"><xsl:value-of select="id"/></td>
<td align="center"><xsl:value-of
select="email"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

OUTPUT:
Bank example Using XSLT:

CODE:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="bank.xsl"?>
<bank>
<account>
<acc_no>A-101</acc_no>
<branch_name>DOWN TOWN</branch_name>
<balance>500</balance>
</account>
<account>
<acc_no>A-102</acc_no>
<branch_name>Perry ridge</branch_name>
<balance>500</balance>
</account>
<account>
<acc_no>A-103</acc_no>
<branch_name>DOWN TOWN</branch_name>
<balance>1000</balance>
</account>
</bank>
XSLT stylesheet:

CODE:
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<html>
<body>
<h2>BANK</h2>
<table border="1">
<xsl:for-each select="bank/account">
<tr>
<td><xsl:value-of select="acc_no"/></td>
<td><xsl:value-of select="branch_name"/></td>
<td><xsl:value-of select="balance"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
OUTPUT:
JDBC Examples:

Create table DEMO:

CODE:
import java.sql.*;
import java.io.*;

public class create


{
public static void main(String[] args)
{
Connection con;
Statement st;
int x=1;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:bi
ndhu");
st=con.createStatement();
BufferedReader bin=new BufferedReader(new
InputStreamReader(System.in));
x=st.executeUpdate("create table student(age int,sname
varchar(20))");
if(x!=-1)
System.out.println("table created succesfully");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

OUTPUT:
Insert Demo:
CODE:
import java.sql.*;
import java.io.*;

public class insert


{
public static void main(String[] args)
{
Connection con;
Statement st;
int x=1;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con=DriverManager.getConnection("jdbc:odbc:bindhu");
st=con.createStatement();
BufferedReader bin=new
BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<5;i++)
{
System.out.println("Enter sudent name:");
String sname=bin.readLine();
System.out.println("Enter sudent age:");
String age=bin.readLine();
x=st.executeUpdate("insert into student
values("+age+",'"+sname+"')");
//System.out.println(x);
x=x+i;
}
if(x!=-1)
System.out.println(x+"records inserted
successfully..");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
OUTPUT:
Update Demo:
CODE:
import java.sql.*;
import java.io.*;

public class update


{
public static void main(String[] args)
{
Connection con;
Statement st;
try
{

con=DriverManager.getConnection("jdbc:odbc:bindhu");
st=con.createStatement();
int f=st.executeUpdate("update student set
sname='sindhu', age=20 where sname='bindhu' ");
if(f!=-1)
System.out.println("record updated..");
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
OUTPUT:

You might also like