1. Write an HTML page
including any required JavaScript that takes a number from one text field in
the range of 0 to 999 and shows it in another text field in words. If the
number is out of range, it should show "out of range" and if it is
not a number, it should show "not a number" message in the result
box.
<html>
<head>
<title>WT Lab
Experiment-2</title>
</head>
<body>
<pre><b>
Input Box : <input type="text"
name="t1" id="t1"> <input type="button"
onclick=test() value="Submit"><br>
Result Box : <input type="text"
name="t2" id="t2"><br>
</b></pre>
<script>
function
test()
{
var x;
x =
document.getElementById("t1").value;
if (x<0)
document.getElementById("t2").value="Out
of Range";
else if(x>999)
document.getElementById("t2").value="Out
of Range";
else if(isNaN(x))
document.getElementById("t2").value="Not
a Number";
else {
var r,s=0,t="";
while(x>0)
{
r
= x%10;
s
= s*10+r;
x
= parseInt(x/10);
}
x = s;
while
(x>0) {
r
= x%10;
if
(r==0)
t
= t+"Zero ";
if
(r==1)
t
= t+"One ";
if
(r==2)
t
= t+"Two ";
if
(r==3)
t
= t+"Three ";
if
(r==4)
t
= t+"Four ";
if
(r==5)
t
= t+"Five ";
if
(r==6)
t
= t+"Six ";
if
(r==7)
t
= t+"Seven ";
if
(r==8)
t
= t+"Eight ";
if
(r==9)
t
= t+"Nine ";
x
= parseInt(x/10);
}
document.getElementById("t2").value
= t;
}
}
</script>
</body>
</html>
OUTPUT
case1
CASE2
CASE3
Comments
Post a Comment