Search This Blog

Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Sunday, 16 September 2012

Practical 36) Write a JSP Page to use JSP scripting.


Filename-FindColor.html

<html>
<body>
<form action="http://localhost:8090/wtad/def36/Scripting.jsp">
color name
<input type="text" name="color"/>
<br>
<input type="submit" />
</form>
</body>
</html>

Filename-Scripting.jsp

<html>
<body bgcolor="<%= request.getParameter("color") %>">
<h2> Scripting Example of jsp </h2>

<br>
<%! int access=0; %>
Current date and time=
<%= new java.util.Date()%>
<br>
Example of Scriplet
<br>
<%
          int myno=(int)(Math.random()*100);
%>
Random Number=
<%= myno %>
<br> visited page time=
<%= ++access %>

<%!
          private int genNumber(int no)
          {
                   java.util.Random r=new java.util.Random();
                   return r.nextInt(no);
          }
%>
<br>Number genrated is under 10=
<%= genNumber(10) %>

<br>
RequestParameter1


</body>
</html>

Output

color name  

Scripting Example of jsp


Current date and time= Tue Apr 10 23:48:45 IST 2012 
Example of Scriplet 
Random Number= 18 
visited page time= 2 
Number genrated is under 10= 8 
RequestParameter1

Thursday, 6 September 2012

Practical-9) Write a JavaScript to show a pop up window with a message Hello and background color lime and with solid black border.


Filename-js9.html

<html>
<head>
<title> Java Practical 9 </title>
<script language="javascript">
         
          function popup()
          {
          //open("js8.html");
                   var pu =window.createPopup();
                   //var ref = pu.documetn.body; //create reference ...
                   pu.document.body.style.backgroundColor="#AAFFFF";
                   pu.document.body.style.border="solid black"
                   pu.show(50,50,200,160,document.body);
                   pu.document.body.innerHTML="Welcome to Apple.com";
          }
</script>
</head>
<body>
<form>
<input type="button" name="bt" value="show pop-up" onClick="popup()">
</form>
</body>
</html>

Output
Note: pop-up windows generate on IE.

Practical-8) Write a JavaScript to find a string from the given text. If the match is found then replace it with another string.


Filename-js8.html

<html>
<head>
          <script language="javascript">
                   function check()
                   {                  frm.str1.value=frm.str1.value.replace(frm.str2.value,frm.str3.value);
                   }
          </script>
</head>
<body>
          <form name="frm">
                   Enter String
                   <input type="text" name="str1" />
                   Enter find String
                   <input type="text" name="str2" />
                   Enter replace string
                   <input type="text" name="str3" />
                   <input type="button" name="button" value="find" onClick="check()" />
          </form>
</body>
</html>

Output

Enter String  Enter find String  Enter replace string  

Practical-7) Write a JavaScript to convert Celsius to Fahrenheit.


Filename-js7.html

<html>
<head>
          <script language="javascript">
                   function cel()
                   {
                             frm.farn.value=((9/5)*(parseInt(frm.cell.value)))+32;
                   }
          </script>
</head>
<body>
          <form name="frm">
                   Enter Celsius
                   <input type="text" name="cell"/>
                   <input type="button" name="far" value="Fahrenheit"onClick="cel()"/>
                   <input type="text" name="farn" readonly="readonly"/>
          </form>
</body>
</html>

Output

Enter Celsius   

Practical-6) Write a JavaScript to remove the highest element from the array and arrange the array in ascending order.


Filename-js6.html

<html>
<head>
<script language="javascript">

var no=new Array(0,1,2,3,33,6,58,89,991);
document.write("Array no are="+no+"<br>");
function compare(a,b)
{
return a-b;
}
document.write("sorting order=");
document.write(no.sort(compare));
//document.write("<br>"+"print"+no.slice(0,no.length));
document.write("<br>"+"remove max no print=");
for(i=0;i<no.length-1;i++)
{
document.write(no[i]+",");
}
<!-- for(i=0;i<no.length;i++)
{
for(j=i;j<no.length;j++)
{
if(no[i]<no[j])
{
//document.write(no[i]);
//var no2=
}
}

}
-->
</script>
</head>
</html>

Output
Array no are=0,1,2,3,33,6,58,89,991 sorting order=0,1,2,3,6,33,58,89,991 remove max no print=0,1,2,3,6,33,58,89


Practical-5) Write a JavaScript to generate two random numbers and find out maximum and minimum out of it.


Filename-s5.html

<html>
<head>
<script language="javascript">
var no1=Math.random()*100;
var no2=Math.random()*100;
document.write("no1="+no1+"<br>");
document.write("no2="+no2+"<br>");

if(no1 > no2)
{
ducument.write("max no="+no1);
}
else
{
document.write("max no"+no2);
}
</script>
</head>
<body>
</body>
</html>

Output
no1=87.61335089802742
no2=77.67163217067719

Practical-4) Write a JavaScript that finds out multiples of 10 in 0 to 10000. On the click of button start the timer and stop the counter after 10 seconds. Display on the screen how many multiples of 10 are found out within stipulated time.


Filename-js4.html

<html>
<head>
<title> Practical 4 </title>
<script language="javascript">
function start_counter()
{
var i=0,count=0;
for(i=1;i<=10000;i++)
{
if(i%10==0)

{
document.write("<br>" + i + "<br>");
count++;
}
}
document.write("<br> Multiplication Of 10 are :- " + count);
}
function call_counter()
{
setTimeout("start_counter()",10000);
}
</script>
</head>
<body>
<form>
<!-- <input type="button" name="b1" value="Start" onClick="start_counter(this.form)"> -->
<input type="button" name="b1" value="Call" onClick="call_counter(this.form)">
</form>
</body>
</html>

Output
10 20 30 40 .
.
.
9970 9980 9990 10000 Multiplication of 10 are: - 1000

Practical-3) Create a Form in HTML with two fields, minimum and maximum, write JavaScript to validate that only numeric value is entered in both, and the value entered in minimum is less than the value entered in maximum.


Filename-js3.html

<html>
<head>
<script language="javascript">
function checkval(myno)
{
if(isNaN(myno.value))
{
alert("plz enter number");

myno.focus();
}
}
function val(no1,no2)
{
if(no1.value> no2.value)
{
alert("plz enter no2 is gretter then no1");
no2.focus();
}
}
function add()
{ frm.result.value=parseInt(frm.minno.value)+parseInt(frm.maxno.value);
}
</script>
</head>
<body>
<form name="frm">
Enter min no=<input type="text" name="minno" onBlur="checkval(this.form.minno)"/>
<br>
Enter max no= <input type="text" name="maxno" onBlur="checkval(this.form.maxno),add(),val(this.form.minno,this.form.maxno)" />

<br>
addtion of two no
<input type="result" name="result" readonly="readonly" onBlur=""/>
</form>
</body>
</html>

Output
Enter min no=
Enter max no=
addtion of two no


practical-2) Write a JavaScript that demonstrates the use of +=,-=,*=,/= operators.


Filename-js2.html

<html>
<body>
<script language="javascript">
a=parseInt(prompt("Enter no1"));

b=parseInt(prompt("Enter no2"));
document.write("a="+a+"<br>");
document.write("b="+b);
c=a;
a+=b;
document.write("<br>"+"c="+a);
</script>
</body>
</html>

Output
a=12 b=10 c=22

practical-1) Write a JavaScript that shows how a variable’s type can be changed on-the-fly.


Filename-js1.html

<html>
<body>
<script language="javascript">
a=10;
document.write("a="+ a +"type="+typeof a+"<br>");
a="hello";
document.write("a="+ a +"type="+typeof a+"<br>");
</script>
</body>
</html>
Output
a=10type=number a=hellotype=string