Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Round Numbers in text boxes two decimal places 2

Status
Not open for further replies.

dugen

Programmer
Jun 16, 2003
59
US
Hi,

I would like to round the numbers in all of my text boxes to 2 decimal places. This is how the form works:

a user puts the quantity of an item in the boxes named tb13 and tb14. Onchange the value of textboxes named number13 and number14 are automatically calculated and put in the textboxes. number13 and number14 are then added and put in the text box named total.

All i need is for the numbers in the text boxes to be rounded to two decimal places.


Here is some code from my form: Thanks,

<input name="tb13" type="text" id="tb13" onchange="this.form['number13'].value=(this.value/1) * (this.form['peach-price'].value/1);this.form['total'].value=(this.form['total'].value)/1 + (this.form['number13'].value)/1;" value="0" size="1" />
$
<input name="number13" type="text" id="number13" size="5" readonly="" />
</label>
<input name="peach-price" type="hidden" id="peach-price" value="17.39" />
</span></td>
</tr>
<tr>
<td bgcolor="#FDF8EA"><span class="style8">Pumpkin Pecan Praline w/ vanilla flavored crust </span></td>
<td bgcolor="#FDF8EA"><span class="style8">Qty:</span> <span class="style8">
<label>
<input name="tb14" type="text" id="tb14" onchange="this.form['number14'].value=(this.value/1) * (this.form['peach-price'].value/1);this.form['total'].value=(this.form['total'].value)/1 + (this.form['number14'].value)/1;" value="0" size="1" />
$
<input name="number14" type="text" id="number14" size="5" readonly="" />
</label>
</span></td>
</tr>
<tr>
<td bgcolor="#FBEAB4">&nbsp;</td>
<td bgcolor="#FBEAB4">_____________________</td>
</tr>
<tr>
<td bgcolor="#FDF8EA"><div align="right"><span class="style8">TOTAL:</span></div></td>
<td bgcolor="#FDF8EA"><label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$



<input name="total" type="text" id="total" size="5" readonly="" />
</label></td>
 
you can use this function

Code:
<script type="text/javascript"><!--
function doRound(o) {
    o.value = parseFloat(o.value).toFixed(2);
}//--></script>

call it like this from your text boxes:

Code:
<input type="text" name="t1" onblur="doRound(this);" />



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
How about something like:
Code:
<input name="tb13" type="text" id="tb13" onchange="this.form['number13'].value=this.value1 * this.form['peach-price'].value;this.form['total'].value=((this.form['total'].value/1) + (this.form['number13'].value/1)).toFixed(2);" value="0" size="1" />

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top