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
  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Exclamation Javascript ignoring decimal

    Hey. I have a onclick event to change the value of a disabled textbox depending on which radio button is checked...

    Code:
    pay monthly or yearly?
    <label>
    <input type="radio" name="billing" value="monthly" onclick="document.forms['starter']['amount'].value=2.50">
    Pay £2.50 monthly</label>
    <label>
    <input type="radio" name="billing" value="yearly" onclick="document.forms['starter']['amount'].value=25.00">
    Pay £25.50 yearly</label>
    <p>  <br>
    
    amount due: 
      £<input name="amount" type="text" disabled="true" value="0.00" size="6" maxlength="6">
    But as you can see from this rather crude first design of the page here I want to use it on, it ignores the decimal place and everything after it and my order processing needs the $amount to be in 25.00 format.

    What needs to go before the dot or whatever to make it process it and the numbers after it?


    Thank you in advance.

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you are supporting browsers IE5.5++ compatable...
    You can use: toFixed(2) else you will need multiply by 100 and Math.Round().... For the later, search this forum and you will find numerous examples... I believe, there is even an example on this front page....

    Code:
    <form>
    pay monthly or yearly?
    <label>
    <input type="radio" name="billing" value="monthly" 
    onclick="this.form['amount'].value=2.50.toFixed(2)">
    Pay £2.50 monthly</label>
    <label>
    <input type="radio" name="billing" value="yearly" 
    onclick="this.form['amount'].value=25.00.toFixed(2)">
    Pay £25.50 yearly</label>
    <p>  <br>
    
    amount due: 
      £<input name="amount" type="text" disabled="true" value="0.00" size="6" maxlength="6">
    </form>
    .....Willy


  •  

    Posting Permissions

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