473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 1747
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

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

Similar topics

0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.