0

I'm stuck on this project and not sure what's going wrong. I need to return the temp conversion of a users input on click. Any help would be appreciated.

<!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" lang="en" xml:lang="en">

<head>
   <title>Temperature Converter</title>
      <script type = "text/javascript">
 	 <!--
              
	     function calculateCelsius()
		{
 		var form = document.getElementById("formTemp");
		var value =  parseInt(form.fahrenheitInput.value);
 		form.celsiusInput.value = celsius(value);
		
		var C = 0;
		C = 9.0 / 5.0 * celsiusInput + 32 +"F";
		
		return C;
		}
		
 	     function calculateFahrenheit()
		{
		var form = document.getElementById("formTemp");
		var value = parseInt(form.celsiusInput.value);
 		form.fahrenheitInput.value = fahrenheit(value);

		var F = 0;
		F = (5.0 / 9.0 * (fahrenheitInput- 32)+"C");

		return F;
		}



     </script>
 </head>

 <body>
   <form ID="formTemp">
      	
	   <p>Fahrenheit</p>
	   <input name = "fahrenheitInput" type = "text" />
	   <input type = "button" value = "Convert to Celsius" onclick = "calculateCelsius()" />
 	
	   <p>Celsius</p>
 	   <input name = "celsiusInput" type = "text" />
	   <input type = "button" value = "Convert to Fahrenheit" onclick = "calculateFahrenheit()" />
 	    
   </form>
 </body>
 </html>
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by McFae
0
<!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" lang="en" xml:lang="en">

<head>
  <title>Temperature Converter</title>
    <script type = "text/javascript">
    <!--
    function calculateCelsius() {
      var form = document.getElementById("formTemp");
      var value =  parseInt(form.fahrenheitInput.value);
      form.celsiusInput.value = (9.0 / 5.0 * value + 32) +"F";
    }
		
    function calculateFahrenheit() {
      var form = document.getElementById("formTemp");
      var value = parseInt(form.celsiusInput.value);
      form.fahrenheitInput.value = (5.0 / 9.0 * (value-32))+"C";
    }
    </script>
  </head>

 <body>
   <form ID="formTemp">
     <p>Fahrenheit</p>
     <input name = "fahrenheitInput" type = "text" />
     <input type = "button" value = "Convert to Celsius" onclick = "calculateCelsius()" />
 	
     <p>Celsius</p>
     <input name = "celsiusInput" type = "text" />
     <input type = "button" value = "Convert to Fahrenheit" onclick = "calculateFahrenheit()" />
   </form>
 </body>
 </html>

I hope you look at this code and give you a better idea about how to work with HTML elements. Not have much time to explain right now, sorry...

Edited by Taywin: n/a

0

Definitely, just got out of basic HTML and now starting to work with javascript. It is still a bit confusing at the moment.
Thank you so much

I hope you look at this code and give you a better idea about how to work with HTML elements. Not have much time to explain right now, sorry...

Edited by happygeek: fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.