<html> <head> <script type="text/javascript"> function convert(degree) { if (degree=="C") { F=document.myform.celsius.value * 9 / 5 + 32 document.myform.fahrenheit.value=Math.round(F) } else { C=(document.myform.fahrenheit.value -32) * 5 / 9 document.myform.celsius.value=Math.round(C) } } </script> </head> <body> <b>Insert a number in either input field, and the number will be converted into either Celsius or Fahrenheit.</b> <br /> <form name="myform"> <input name="celsius" onkeyup="convert('C')"> degrees Celsius<br /> equals<br /> <input name="fahrenheit" onkeyup="convert('F')"> degrees Fahrenheit </form> <br /> Note that the <b>Math.round</b> method is used, so that the result will be returned as a whole number. </body> </html>
Edit the text above, and click on the button to see the result.
Copyright © 2007-2008, Www.JavaBasics.We.Bs All rights reserved.