You can use some of the various currency formatting scripts out there
to format the currency after the calculation has taken place.
Unfortunately, then you also have to un-format it when you go to
recalculate the price again or you're going to get NaN. I suggest
just putting a "$" (or local currency symbol) in front of the input
and make your life easier. Here's a script, I found with a quick
Google search (http://javascript.internet.com/forms/currency-
format.html):
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
HTH,
Jon
On Jan 13, 2007, at 2:02 PM, Doug Brown wrote:
> I found it. I had a numberFormat() in there. How would I format the
> result
> to be like dollarFormat()? I appreciate the help.
>
> Doug B.
> ----- Original Message -----
> From: "Jon Clausen" <[EMAIL PROTECTED]>
> To: "CF-Talk" <[email protected]>
> Sent: Saturday, January 13, 2007 11:58 AM
> Subject: Re: A little JS help!!
>
>
>> Do you have numeric default set for your #itemPrice# variable? If
>> not, you'll either have to pull the window.onload function or set a
>> numeric default.
>>
>> Also, does DOM of your page validate?
>>
>> Jon
>>
>> On Jan 13, 2007, at 1:50 PM, Doug Brown wrote:
>>
>>> Jon, Thanks for the help. When I run the code I get NaN
>>>
>>>
>>>
>>>
>>> Doug B.
>>> ----- Original Message -----
>>> From: "Jon Clausen" <[EMAIL PROTECTED]>
>>> To: "CF-Talk" <[email protected]>
>>> Sent: Saturday, January 13, 2007 11:31 AM
>>> Subject: Re: A little JS help!!
>>>
>>>
>>>> I'd suggest changing your HTML a bit to make it easier. I removed
>>>> the calculate button because you don't need it, but you could
>>>> always
>>>> put it back and set the onclick to setTotal().
>>>>
>>>> With the changed HTML the following will work:
>>>>
>>>> <script type="text/javascript" language="javascript">
>>>> function setTotal() {
>>>> var calcs = document.getElementsByTagName('input');
>>>> var qty = 0;
>>>> var price = 0;
>>>> for(var i=0; i < calcs.length; i++) {
>>>> if (calcs[i].getAttribute('name') == "price"){
>>>> price = (price+calcs[i].value);
>>>> };
>>>> if (calcs[i].getAttribute('name') == "AQuantity"){
>>>> qty = (qty+calcs[i].value);
>>>> };
>>>> };
>>>> document.getElementById("total-price").innerHTML = (qty * price);
>>>> }
>>>> window.onload = function(){
>>>> setTotal();
>>>> }
>>>> </script>
>>>>
>>>> <tr>
>>>> <td width="70" class="bblackfont">Your Offer:</td>
>>>> <td width="80" class="nblackfont"><input type="text"
>>>> name="AQuantity" value="1" style="width: 40px;" onblur="setTotal
>>>> ()"></
>>>> td>
>>>> <td width="590" class="nblackfont"><input type="text"
>>>> name="price" value="#numberFormat(itemPrice)#" style="width:50px;"
>>>> onblur="setTotal()"></td>
>>>> <td id="total-price"><!---totalPrice goes here---></td>
>>>> </tr>
>>>>
>>>>
>>>>
>>>>
>>>> On Jan 13, 2007, at 12:56 PM, Doug Brown wrote:
>>>>
>>>>> I have the following little code snippet and what I would like to
>>>>> do is update the totalPrice if the quantity is changed by the
>>>>> user.
>>>>>
>>>>> <TR>
>>>>> <TD width="70" class="bblackfont">Your Offer:</TD>
>>>>> <TD width="80" class="nblackfont"><input type="text"
>>>>> name="AQuantity" value="1" style="width: 40px;"></TD>
>>>>> <TD width="590" class="nblackfont"><input type="text"
>>>>> name="price" value="#numberFormat(itemPrice)#" style="width:
>>>>> 50px;"></TD>
>>>>> <TD><!---totalPrice goes here---></TD>
>>>>> <TD><image src="images/calulator.gif" alt="calculate"
>>>>> onClick="something"></TD>
>>>>> </TR>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Doug B.
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create robust enterprise, web RIAs.
Upgrade & integrate Adobe Coldfusion MX7 with Flex 2
http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:266510
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4