By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,453 Members | 961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,453 IT Pros & Developers. It's quick & easy.

New to java, Basic help needed please

P: 2
Ive been asked to make a function to Convert Fahrenheit to Celsuis, via the on screen interface of the web page, nothing seems to be working for me, and i can not see whats wrong, please help

[HTML]
<<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Temp</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type = "text/css">
body { background-color: #ddd }
</style>
<script language = "JavaScript" type="text/javascript">

function FtoC(r) {
return Math.round (F = 9.0/5.0*r+32 );

}

function FtoC() {
din = document.getElementById("inputVal");
dout = document.getElementById("outputVal");
dout.value = FtoC(din.value);

}

</script>
</head>
<body>
<h1> Temp</h1>
<form name = "myForm" id="myForm" action="">
<table border = "1">

<tr>
<td><b>Enter Temp</b></td>
<td><input id="inputVal" name = "inputVal" type = "text" /></td>
</tr>
<tr>
<td><b>The answer is</b></td>
<td><input name = "outputVal" id="outputVal" type = "text" /></td>
</tr>

<tr>
<td><input name = "calculate" type = "button" value = "Calculate"
onclick = "FtoC()" /></td>
</tr>
</table>
</form>
</body>
</html>
[/HTML]
Nov 16 '06 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 1,892
Try this:

[html]<html>
<head>
<script type="text/javascript">
function convert(degree)
{
if (degree=="C")
{
F=document.myform.celsius.value * 9 / 5 + 32
document.myform.fahrenheit.value=(F)
}
else
{
C=(document.myform.fahrenheit.value -32) * 5 / 9
document.myform.celsius.value=(C)
}
}
</script>
</head>
<body>
<form name="myform">
<input name="celsius" onkeyup="convert('C')" size="20"> degrees Celsius<br />
equals<br />
<input name="fahrenheit" onkeyup="convert('F')" size="20"> degrees Fahrenheit
</form>
</body>
</html>
[/html]
Nov 16 '06 #2

P: 2
THanks for your reply, but i have to use the function, cant use anything eles, if, else = no no :(
Nov 16 '06 #3

iam_clint
Expert 100+
P: 1,208
Heres yoru code

you can't use two functions with the same name thats ambiguous.

[HTML]
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Temp</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type = "text/css">
body { background-color: #ddd }
</style>
<script language = "JavaScript" type="text/javascript">
function FtoC(r) {
din = document.getElementById("inputVal");
dout = document.getElementById("outputVal");
dout.value = Math.round(F = 9.0/5.0*din.value+32 );
}
</script>
</head>
<body>
<h1> Temp</h1>
<form name = "myForm" id="myForm" action="">
<table border = "1">

<tr>
<td><b>Enter Temp</b></td>
<td><input id="inputVal" name = "inputVal" type = "text" /></td>
</tr>
<tr>
<td><b>The answer is</b></td>
<td><input name = "outputVal" id="outputVal" type = "text" /></td>
</tr>

<tr>
<td><input name = "calculate" type = "button" value = "Calculate"
onclick = "FtoC()" /></td>
</tr>
</table>
</form>
</body>
</html>
[/HTML]
Nov 16 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.