...

View Full Version : how to do this



xiaodao
06-29-2006, 12:08 PM
i have a form



<input type="text" name="haha"><br/>




then i have a formular


cost=haha*0.7

how can i do instant showing when i input a value into the text field of "haha", mean, i enter the value of haha example 10 into the value, cost striaght show 7

Kor
06-29-2006, 12:35 PM
<form>
<input type="text" name="haha" onkeyup="this.form['cost'].value=Number((this.value*0.7).toFixed(2))">
<br>
<input type="text" name="cost">
</form>


I have used the combination Number() & toFixed() to avoid a possible error, as math operation with floated might accumulate small errors during binary-decimal-binary translation (the CPU uses binary to calculate and some decimal floated numbers are not finite in binary)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum