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

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

I tried , that is gooood.


Thank hielo very much..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.