Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: how to do this

  1. #1
    Regular Coder
    Join Date
    Sep 2004
    Posts
    713
    Thanks
    6
    Thanked 2 Times in 2 Posts

    how to do this

    i have a form

    Code:
    <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
    flying dagger

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Code:
    <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)
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •