topical media & game development

talk show tell print

basic-javascript-06-ch06-q1.htm / htm



  <html>
  <head>
  <script language="JavaScript" type="text/javascript">
  function convertToCentigrade(degFahren)
  {
     var degCent;
     degCent = 5/9 * (degFahren - 32);
     
     return degCent;
  }
  
  function butToCent_onclick()
  {
     var CalcBox = document.form1.txtCalcBox;
  
     if (isNaN(CalcBox.value) == true || CalcBox.value == "")
     {
        CalcBox.value = "Error Invalid Value";
     }
     else
     {
        CalcBox.value = convertToCentigrade(CalcBox.value);
     }
  }
  </script>
  </head>
  <body>
  
  <form name=form1>
  <P>
     <input type="text" name=txtCalcBox value="0.0">
  </P>
     <input type="button" 
           value="Convert to centigrade" 
           name=butToCent
           onclick="butToCent_onclick()">
  </form>
  </body>
  </html>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.