black_pigeon
Apr 23rd 2009, 6:02 pm
I'm a js noob trying to piece together two functions and I can't seem to make it work. I want to calculate the volume of form inputs and round to two decimal places. Here's what I'm trying:
VOLUME:
function Rec(form)
{form.an4.value = form.length4.value * form.width4.value * (form.height4.value/12) * .037}
ROUNDING:
function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
document.roundform.this.form.value = newnumber; // Output the result to the form field (change for your purposes)
FORM:
<p>length in feet <input type="text" name="length4"></p>
<p>width in feet <input type="text" name="width4"></p>
<p>depth in inches <input type="text" name="height4"></p>
<p><input type="button" class="submit" onClick="Rec(this.form)" value="Find Volume"></p>
<p><input type="text" name="an4"> <strong>CUBIC YARDS</strong></p>
The volume function works, but I'm not sure how to incorporate the rounding. I have two other volume calculations on this page in the same form, so I thought I needed to call the rounding from each volume function.
When you reply, speak slowly and with lots of arm waving - I might get what you're talking about. Thanks!
VOLUME:
function Rec(form)
{form.an4.value = form.length4.value * form.width4.value * (form.height4.value/12) * .037}
ROUNDING:
function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
document.roundform.this.form.value = newnumber; // Output the result to the form field (change for your purposes)
FORM:
<p>length in feet <input type="text" name="length4"></p>
<p>width in feet <input type="text" name="width4"></p>
<p>depth in inches <input type="text" name="height4"></p>
<p><input type="button" class="submit" onClick="Rec(this.form)" value="Find Volume"></p>
<p><input type="text" name="an4"> <strong>CUBIC YARDS</strong></p>
The volume function works, but I'm not sure how to incorporate the rounding. I have two other volume calculations on this page in the same form, so I thought I needed to call the rounding from each volume function.
When you reply, speak slowly and with lots of arm waving - I might get what you're talking about. Thanks!