0

Hi to all .


I write the JS code :

<?xml version = "1.0"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">    
    <html xmlns = "http://www.w3.org/1999/xhtml">


<head>
<title>TemperaturE</title>

<script type = "text/javascript">
function temperature()
{
     var temperatureValue = myForm.TemperatureField.value;

     if ( temperatureValue < 20)
          {document.body.style.backgroundColor  = "Blue";}

     if (temperatureValue  <40)
          {document.body.style.backgroundColor  = "Yellow";}

     if (temperatureValue  > 40)
          {document.body.style.backgroundColor  = "Red";}

}
  // -->
</script>
</head>

    <body>
        <form name = "myForm" action = ""> 
           <label>Please,enter the city current temperature: <input name = "TemperatureField" type = "text" value = "" />  </label>
           <input name = "ChangeColor" type = "button" value = "Change Color" onclick = "temperature()" />
        </form>

     </body>
</html>

But not doing the correct output .

If I will add this statement :

document.write ("Hi");

in start of function's body , It printed .
So , the calling is correct, I can't determine error place .

Maybe because browser ?!!!
I tried use with (Internet Explorer ) and (Mozilla Firefox) , but the same result ....


Any body can help me !!!!

Thank you

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by mini programmer
0

try: <form [B]id[/B]="myForm" action = ""> AND var temperatureValue = [B]document.getElementById('myForm')[/B].TemperatureField.value;

This question has already been answered. 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.