...

View Full Version : Javascript ignoring decimal



bridgey
12-27-2004, 02:37 PM
Hey. I have a onclick event to change the value of a disabled textbox depending on which radio button is checked...


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 (http://messhost.com/cardorder.php) 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.

Willy Duitt
12-27-2004, 03:23 PM
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....



<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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum