<head>
<script lang="javascript">
var flag=false;
function change(ele)
{
if(ele.value=="ctof")
{
flag=false;
document.getElementById("msg").innerHTML="<b>DEGREE CELSIUS</b>";
}
else
{
flag=true;
document.getElementById("msg").innerHTML="<b>DEGREE FAHRENHEIT</b>";
}
}
function numvalid()
{
e=event.keyCode;
if( e<48 || e >57)
{
event.keyCode=0;
}
}
function convert(val)
{
result=document.getElementById("ans");
if(flag==false)
{
f=(val*1.8) + 32;
result.innerHTML="FAHRENHEIT = " + f;
}
else
{
c=(val-32)/1.8;
result.innerHTML="CELCIUS = " + c;
}
}
</script>
<body>
<h3>PROGRAM 7 : </h3><h4>TEMPERATURE CONVERSION</h4>
<h4>SELECT CONVERTION:</h4>
<input type="radio" name="conv" value="ctof" checked="true" onclick="change(this)">CELSIUS TO FAHRENHEIT</input><br>
<input type="radio" name="conv" value="ftoc" onclick="change(this)">FAHRENHEIT TO CELSIUS</input><BR><BR>
<div id="msg"><b>DEGREE CELSIUS</b> </div>
<input type="text" id="degC" name="degC" onkeypress="numvalid()" onkeyup="convert(this.value)"/> <br><br>
<div id="ans"></div>
</body>
</head>
No comments:
Post a Comment