Saturday, 14 September 2013

Compute value entered in textbox and place in another textbox?

Compute value entered in textbox and place in another textbox?

I have a form with two text boxes. I want to enter a number on one box,
press the Convert link, and have it compute the number in the first box to
Celsius and place it in the second text box. So far it isn't working and I
feel like there's something small I'm missing... What can I do?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
body
{
background-color: white;
}
h2
{
position: absolute;
left:200px;
top:5px;
color: cadetblue;
}
p
{
text-align: center;
font-family: times new roman;
color: black;
}
</style>
<script>
function f2cCalc(input)
{
var fbox = document.getElementById(input);
var cbox = document.getElementById(cinput);
var f = parseInt(fbox.value);
var cel = Math.round(5/9*(f-32));
document.getElementById(cbox).value=cel;
}
function changeText(inId, txt)
{
var t = document.getElementById(inId);
if(t!=null)
{
t.innerHTML=txt;
}
}
</script>
</head>
<body>
<form method="get" action="">
<h2>Temp calculator</h2>
<br />
<br />
<br/>
<br/>
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
F<input id="finput" type="number" STYLE="background-color:
cadetblue; color: green;" value="0"/>
&nbsp;&nbsp;&nbsp;&nbsp;
C<input id="cinput" type="number" STYLE="background-color:
cadetblue; color: green;" value="0"/>
<a href="javascript:f2cCalc(finput)">Convert</a>
</form>
</body>
</html>
enter code here

No comments:

Post a Comment