- Write a JavaScript that demonstrates the use of +=,-=,*=,/= operators.
//----------
<html>
<head>
<title>Tutorial - 1</title>
</head>
<body>
<script language="javascript">
var n1 = 26;
var n2=parseInt(prompt("Input any Integer No to N2:"));
n1+=n2;
document.write("<font size=4> Value of n1 after Addition is " +n1+"</font></br>");
n1-=n2;
document.write("<font size=4> Value of n1 after Substraction is "+n1+"</font></br>");
n1*=n2; document.write("<font size=4> Value of n1 after Multiplication "+n1+"</font></br>");
n1/=n2;
document.write("<font size=4> Value of n1 after Division "+n1+"</font></br>");
</script>
</body>
</html>
- 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 in maximum.
//----------
<html>
<head>
<script language="javascript">
function checkNums(e)
{
try
{
var unicode;
if(window.event)
unicode=e.keyCode;
else if(e.which)
unicode=e.which;
if(((unicode<48) || (unicode>57)) && (unicode!=8))
return false;
else
return true;
}
catch(err)
{
txt="There was an error on this page.\n";
txt+="Error description: " + err.description + "\n";
txt+="Click OK to continue.\n";
alert(txt);
}
}
function checkmax(n1,n2)
{
n1=parseInt(n1);
n2=parseInt(n2);
if(n1>n2)
{
alert("minimumm value should not exceed maximum value");
maxval.setFocus;
}
}
</script>
<body>
<form action="" name="valueCheck" method="">
Minimum Value :: <input type="text" name="minval" onKeyPress="return checkNums(event);" />
Maximum Value :: <input type="text" name="maxval" onKeyPress="return checkNums(event);" onBlur="checkmax(minval.value,maxval.value);" />
</form>
</body>
</html>
- 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.
//----------
<html>
<head>
<title>Tutorial 1</title>
</head>
<body>
<input type=button value="start" onclick="win();" />
<script language="javascript">
function win()
{
t=window.setTimeout("s();",1000);
}
function s()
{
try
{
v=10;
sum=0;
for(i=0;i<=10000;i++);
{
sum=v*i;
document.writeln("<br> Mutiple Of 10:"+sum);
}
}
catch(err)
{
txt="There was an error on this page.\n";
txt+="Error description: " + err.description + "\n";
txt+="Click OK to continue.\n";
alert(txt);
}
}
</script>
</body>
</html>
- Write A javascript to generate two Random Numbers and find out minimum and maximum out of it
//----------
<html>
<head>
<title>Tutorial 1</title>
</head>
<body>
<Script language="javascript">
try
{
n1=(Math.random()*12);
n2=(Math.random()*12);
document.writeln("<font size=5> First Random Number is :: " + n1 + "</font><br>");
document.writeln("<font size=5> Second Random Number is :: " + n2 + "</font><br>");
if(n1>n2)
document.writeln("<font size=5> N1 is Maximum</font>");
else
document.writeln("<font size=5> N2 is Minimum</font>");
}
catch(err)
{
txt="There was an error on this page.\n";
txt+="Error description: " + err.description + "\n";
txt+="Click OK to continue.\n";
alert(txt);
}
</script>
</body>
</html>
- Write a JavaScript to remove the highest element from the array and arrange the array in ascending order.
//----------
<html>
<head>
<script type="text/javascript">
var a=new Array();
function funadd()
{
a.push(parseInt(document.frm.txtdata.value));
document.getElementById("pera").innerHTML=a;
document.frm.txtdata.value="";
document.frm.txtdata.focus();
}
function funremove()
{
var l=a.length;
for(i=0;i<=l;i++)
{
for(j=i+1;j<l;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
alert("The deleted element is: "+a.splice(l-1,1));
document.getElementById("msg").innerHTML="<b><u>Sorted Array:</u></b>";
document.getElementById("sortdata").innerHTML=a;
}
</script>
</head>
<body>
<form name=frm>
<input type="text" id="txtdata">
<input type=button value="ADD" onclick="funadd();">
<input type=button value="REMOVE" onclick="funremove();">
</br>
</br>
<b><u>Elements In Array:</u></b>
</form>
<p id=pera></p>
<p id=Msg></p>
<p id=sortdata></p>
</body>
</html>
- Write a JavaScript to convert Celsius to Fahrenheit.
//----------
<html>
<body>
<form name="mywin">
<input type="text" name="txt1" />
<input type="button" name="click" value="Compute" onClick="win();"/>
</form>
<script language="javascript">
function win()
{
var v=document.mywin.txt1.value;
var f=0;
f=(v*1.8)+32;
alert(f);
}
</script>
</body>
</html>
- Write a JavaScript to find a string from the given text. If the match is found then replace it with another string
//----------
<html>
<head>
<script type="text/javascript">
function findout(form)
{
var str=new String(form.strng.value);
form.strng.value=str.replace(form.find.value,form.replace.value);
}
</script>
</head>
<body >
<form>
Enter a Text : <input type="text" name="strng" size=50><br/><br/>
Word to find : <input type="text" name="find" ><br/>
Word to Replace : <input type="text" name="replace"><br/>
<input type="button" value="REPLACE" onClick="findout(this.form)">
</form>
</body>
</html>
- Write a JavaScript to show a pop up window with a message Hello and background color lime and with solid black border.
//----------
<html>
<head>
<title>JavaScript Popup Example</title>
</head>
<script type="text/javascript">
function poponload()
{
testwindow = window.open("", "mywindow", "location=1,status=1,scrollbars=1,width=300,height=100,border:2px solid #ffffff;");
testwindow.moveTo(200, 200);
testwindow.document.write('<h1>HELLO!</h1>');
testwindow.document.bgColor = "#BFFF00";
}
</script>
<body onload="poponload()">
<h1>JavaScript Popup Example 3</h1>
</body>
</html>
- Write a Servlet to display "Hello World" on browser
//----------
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws IOException,ServletException
{
PrintWriter out=res.getWriter();
out.println("Hello World");
}
}
Prepared By:
Student of B. H. Gardi College of Eng. & Tech., MCA Department
(Nisarg Juthani, Kajal Savjani, Desai Paresh, Ramoliya Nilesh, Thanki Ravi.....)
No comments:
Post a Comment