Javascript Calculation
<p>here the below coding the output value is display in div tag. but i want to display in text box. and another one i want that first text box value is  come from db using php. please help me.</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;style&gt;
.test {
    color:red;
}
#total {
    font-size:40px;
}
h1 {
    margin: 0 0 10px 0;
    text-decoration: underline;
    text-align: center;
}
h2 {
    margin: 0 0 10px 0;
}
&lt;/style&gt;
&lt;script&gt;
  calculate = function(totalElement)
  {
      if (totalElement)
      {   
          var calculation  = '';
          var overall = '';
          var fields = new Array();
          var theElement = document.getElementById(totalElement);
          var userInputs = myform.elements;
          var the_type = '';
          for (var f = 0; f &lt; userInputs.length; f++)
          { 
              if (userInputs[f].className=='special_value')
              {
                  if (userInputs[f].type=='select-one')
                  {
                      if(userInputs[f].options[userInputs[f].selectedIndex].value)
                      {
                          fields[f] = userInputs[f].options[userInputs[f].selectedIndex].value;
                      }
                      else
                      {
                          fields[f] = 0;
                      }
                  }
                  else if(userInputs[f].type=='radio' || userInputs[f].type=='checkbox')
                  {
                      if (userInputs[f].checked)
                      {
                          fields[f] = userInputs[f].value;
                      }
                      else
                      {
                          fields[f] = 0;
                      }
                  }
                  else
                  {
                      if (userInputs[f].value)
                      {
                          fields[f] = userInputs[f].value;
                      }
                      else
                      {
                          fields[f] = 0;
                      }
                  }
              }
          }

          for (var i=0; i&lt;fields.length; i++)
          { 
              calculation += fields[i];

              if (i!=fields.length-1)
              {
                  calculation += '+';
              }
          }

          if (calculation!='')
          {
              overall = eval(calculation).toFixed(2);
          }

          if (overall!='')
          {
              theElement.innerHTML = '&amp;pound;'+overall;
          }
      }
  }
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form name="myform"&gt;
&lt;input onKeyPress="calculate('total');" onBlur="calculate('total');" class="special_value" type="text" name="price"&gt; &lt;Br/&gt;
&lt;input onKeyPress="calculate('total');" onBlur="calculate('total');" class="special_value" type="text" name="price2"&gt; &lt;Br/&gt;
&lt;input onKeyPress="calculate('total');" onBlur="calculate('total');" class="special_value" type="text" name="price4"&gt; &lt;Br/&gt;
&lt;div id="total"&gt;&lt;/div&gt;
&lt;input onClick="calculate('total');" type="button" name="button" value="re-calculate"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
