J
JS
I've managed to create a simple script to convert between metric and
imperial. It works for CMS to INCHES and vice versa but not for KGS to
STONES/POUNDS. Can anyone shed any light on this?
Here's my code (CMS and INCHES which is working):
<input name="CM" type="text" VALUE="" size="3" maxlength="3"
onChange="eval('IN.value = ' + this.form.IN_expr.value)">
cms <em>or</em>
<input name="IN" type="text" VALUE="" size="3" maxlength="3"
onChange="eval('CM.value = ' + this.form.CM_expr.value)">
inches<INPUT TYPE="hidden" NAME="CM_expr" VALUE="(Math.round(2.54 *
IN.value))">
<INPUT TYPE="hidden" NAME="IN_expr" VALUE="(Math.round(CM.value /
2.54))">
Here's my code for KGS to STONES/POUNDS (not working):
<input name="KGM" type="text" VALUE="" size="3" maxlength="3"
onChange="eval('ST.value = ' + this.form.ST_expr.value);
eval('PNDS.value = ' + this.form.PNDS_expr.value)">
KGM <em>or</em>
<input name="ST" type="text" VALUE="" size="3" maxlength="3"
onChange="eval('KGM.value = ' + this.form.KGM_expr.value)">St
<input name="PNDS" type="text" VALUE="" size="3" maxlength="3"
onChange="eval('KGM.value = ' + this.form.KGM_expr.value)">
lbs
<INPUT TYPE="hidden" NAME="KGM_expr" VALUE="(Math.round((ST.value * 14)
+ PNDS.value) * 0.4536)">
<INPUT TYPE="hidden" NAME="ST_expr" VALUE="(Math.round(KGM.value /
0.4536) / 14)"><INPUT TYPE="hidden" NAME="PNDS_expr"
VALUE="(Math.round(KGM.value / 0.4536) - ST.value)">
Firstly, I only want an integer in the result but am getting a decimal
to about 6 places.
Secondly, it appears that the + in (Math.round((ST.value * 14) +
PNDS.value) * 0.4536) is appending the PNDS.value to the ST.value * 14
so if PNDS.value is 0 and ST.value is 12 it calculates using 120.
I've spent a good few hours trying to get it to work or find the
suitable code but just can't find it.
Many thanks in anticipation.
imperial. It works for CMS to INCHES and vice versa but not for KGS to
STONES/POUNDS. Can anyone shed any light on this?
Here's my code (CMS and INCHES which is working):
<input name="CM" type="text" VALUE="" size="3" maxlength="3"
onChange="eval('IN.value = ' + this.form.IN_expr.value)">
cms <em>or</em>
<input name="IN" type="text" VALUE="" size="3" maxlength="3"
onChange="eval('CM.value = ' + this.form.CM_expr.value)">
inches<INPUT TYPE="hidden" NAME="CM_expr" VALUE="(Math.round(2.54 *
IN.value))">
<INPUT TYPE="hidden" NAME="IN_expr" VALUE="(Math.round(CM.value /
2.54))">
Here's my code for KGS to STONES/POUNDS (not working):
<input name="KGM" type="text" VALUE="" size="3" maxlength="3"
onChange="eval('ST.value = ' + this.form.ST_expr.value);
eval('PNDS.value = ' + this.form.PNDS_expr.value)">
KGM <em>or</em>
<input name="ST" type="text" VALUE="" size="3" maxlength="3"
onChange="eval('KGM.value = ' + this.form.KGM_expr.value)">St
<input name="PNDS" type="text" VALUE="" size="3" maxlength="3"
onChange="eval('KGM.value = ' + this.form.KGM_expr.value)">
lbs
<INPUT TYPE="hidden" NAME="KGM_expr" VALUE="(Math.round((ST.value * 14)
+ PNDS.value) * 0.4536)">
<INPUT TYPE="hidden" NAME="ST_expr" VALUE="(Math.round(KGM.value /
0.4536) / 14)"><INPUT TYPE="hidden" NAME="PNDS_expr"
VALUE="(Math.round(KGM.value / 0.4536) - ST.value)">
Firstly, I only want an integer in the result but am getting a decimal
to about 6 places.
Secondly, it appears that the + in (Math.round((ST.value * 14) +
PNDS.value) * 0.4536) is appending the PNDS.value to the ST.value * 14
so if PNDS.value is 0 and ST.value is 12 it calculates using 120.
I've spent a good few hours trying to get it to work or find the
suitable code but just can't find it.
Many thanks in anticipation.