469,909 Members | 1,815 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,909 developers. It's quick & easy.

Javascript - Form result to 2 Decimal Points

1
Hi
I have a Web Form which I need to get results shown to 2 decimal points only.

In the Head I have: -
function heatoutput()
{
var vWidth=document.heatcalculator.roomwidth.value;
var vLength=document.heatcalculator.roomlength.value;
var vHeight=document.heatcalculator.roomheight.value;

var vRoomSize=vWidth*vLength*vHeight;
var rlength = 2

if(document.heatcalculator.calcunits.selectedIndex == 0)
{vRoomSize=vRoomSize*0.028368;}

document.heatcalculator.result.value=((vRoomSize / 14));
}

And the Form is: -
<FORM name="heatcalculator" method="post">
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="0" bgcolor="#CC0000">
<tbody>
<tr>
<td><table cellspacing="0" cellpadding="10" width="100%" border="0">
<tbody>
<tr>
<td><h1 class="Price_Special">Heat output calculator</h1>
<p class="Price_Special">Simply key in your room measurements, choose the correct units and click the "equals" button to find the heat output required to adequately heat your room.</p></td>
</tr>
<tr>
<td><div align="center"><strong class="Price_Special">Room measurements in:</strong>
<select name="calcunits">
<option value="feet">Feet</option>
<option value="metres" selected>Metres</option>
</select>
</div></td>
</tr>
<tr valign="center">
<td><div align="center" class="Price_Special"><strong>Length:
<input size="2" name="roomlength">
&nbsp;&nbsp;&nbsp;&nbsp;Width:
<input size="2" name="roomwidth">
&nbsp;&nbsp;&nbsp;&nbsp;Height:
<input size="2" name="roomheight">
</strong></div></td>
</tr>
<tr valign="center">
<td><div align="center" class="Price_Special"><strong><a href="javascript:heatoutput()"><img src="Images/equals.gif" alt="Click for result!" width="24" height="24" border="0" align="absBottom" class="Price_Special"></a> &nbsp;
<input size="10" name="result">
&nbsp;kW of heat output needed.</strong></div></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
</FORM>

How do I change this to show answer to 2 decimal points, please?

Many thanks.
Ianhen
Dec 30 '06 #1
1 1561
jai80
30
Hi
I have a Web Form which I need to get results shown to 2 decimal points only.

In the Head I have: -
function heatoutput()
{
var vWidth=document.heatcalculator.roomwidth.value;
var vLength=document.heatcalculator.roomlength.value;
var vHeight=document.heatcalculator.roomheight.value;

var vRoomSize=vWidth*vLength*vHeight;
var rlength = 2

if(document.heatcalculator.calcunits.selectedIndex == 0)
{vRoomSize=vRoomSize*0.028368;}

document.heatcalculator.result.value=((vRoomSize / 14));
}

And the Form is: -
<FORM name="heatcalculator" method="post">
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="0" bgcolor="#CC0000">
<tbody>
<tr>
<td><table cellspacing="0" cellpadding="10" width="100%" border="0">
<tbody>
<tr>
<td><h1 class="Price_Special">Heat output calculator</h1>
<p class="Price_Special">Simply key in your room measurements, choose the correct units and click the "equals" button to find the heat output required to adequately heat your room.</p></td>
</tr>
<tr>
<td><div align="center"><strong class="Price_Special">Room measurements in:</strong>
<select name="calcunits">
<option value="feet">Feet</option>
<option value="metres" selected>Metres</option>
</select>
</div></td>
</tr>
<tr valign="center">
<td><div align="center" class="Price_Special"><strong>Length:
<input size="2" name="roomlength">
&nbsp;&nbsp;&nbsp;&nbsp;Width:
<input size="2" name="roomwidth">
&nbsp;&nbsp;&nbsp;&nbsp;Height:
<input size="2" name="roomheight">
</strong></div></td>
</tr>
<tr valign="center">
<td><div align="center" class="Price_Special"><strong><a href="javascript:heatoutput()"><img src="Images/equals.gif" alt="Click for result!" width="24" height="24" border="0" align="absBottom" class="Price_Special"></a> &nbsp;
<input size="10" name="result">
&nbsp;kW of heat output needed.</strong></div></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
</FORM>

How do I change this to show answer to 2 decimal points, please?

Many thanks.
Ianhen
hi there,

try this:

function heatoutput()
{
var vWidth=document.heatcalculator.roomwidth.value;
var vLength=document.heatcalculator.roomlength.value;
var vHeight=document.heatcalculator.roomheight.value;

var vRoomSize=vWidth*vLength*vHeight;
var rlength = 2

if(document.heatcalculator.calcunits.selectedIndex == 0)
{vRoomSize=vRoomSize*0.028368;}

var res;
res=((vRoomSize/14));
document.heatcalculator.result.value=res.toFixed(2 );

}

hope this solves ur problem. Gud Luck!

cheers,
jai
Jan 10 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.