• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Format Field For Dollar Amount

Format Field For Dollar Amount 8 years 2 months ago #34087

  • ekelly3
  • ekelly3's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 9
Hello,

I would like to format the "Donation" field for USD amount. For example, If a user types in 10, the form will format it to show $10.00. I would like the $ symbol to be in the form field from the start as well.

Can someone please explain to me how this is accomplished? This information will also help me with formatting other parts of my forms. Thanks.
The administrator has disabled public write access.

Format Field For Dollar Amount 8 years 1 month ago #34220

To make sure the entry has 2 decimal points when the form is submitted I used this method:

In Form Properties > CSS & Javascript add this to the Javascript section

<script type="text/javascript">
function formatGift(){
document.getElementById('donation').value = parseFloat(document.getElementById('donation').value).toFixed(2);}
</script>

Substitute 'donation' with the exact name of your donation field.

Then go the the Attributes tab of your form's submit button and enter the trigger in the Additional Attributes field

onclick="formatGift();"

When the submit button is clicked, the donation field will be formatted as 25.00 if the user enters 25. And if they enter 25.99 the 25.99 is entered.

If you also want to add the dollar sign you could probably use

<script type="text/javascript">
function formatGift(){
document.getElementById('donation').value = "$ " + parseFloat(document.getElementById('donation').value).toFixed(2);}
</script>

Hope this is helpful.
The administrator has disabled public write access.

Format Field For Dollar Amount 8 years 1 month ago #34235

After some additional testing, I modified the script so that if the donation box is left empty a "NaN" result isn't returned:

<script type="text/javascript">
function formatGift()
{
if((document.getElementById('donation').value == '0') || (document.getElementById('donation').value.length != 0))
{
document.getElementById('donation').value = parseFloat(document.getElementById('donation').value).toFixed(2);
}
else
{
document.getElementById('donation').value = "0.00";
}
}
</script>
Last Edit: 6 years 9 months ago by support335.
The administrator has disabled public write access.

Format Field For Dollar Amount 6 years 2 months ago #37844

hello
i want display price without 00
i fix decimal=0 but display price with 00
please help me
The administrator has disabled public write access.

Format Field For Dollar Amount 6 years 2 months ago #37856

Did you try this?

<script type="text/javascript">
function formatGift()
{
if((document.getElementById('Donation').value == '0') || (document.getElementById('Donation').value.length != 0))
{
document.getElementById('Donation').value = parseFloat(document.getElementById('Donation').value).toFixed(0);
}
else
{
document.getElementById('Donation').value = "0";
}
}
</script>

But if the user enters 50.50 the number will be rounded up to 51.

If you also want to remove the decimals from the Total displayed, change that in Configuration > Payment tab > Number of Decimals field.

Hope that is helpful.
The administrator has disabled public write access.

Format Field For Dollar Amount 3 years 10 months ago #40205

  • Crispin
  • Crispin's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 73
  • Thank you received: 4
This works a treat, thank you.
The administrator has disabled public write access.

Format Field For Dollar Amount 1 year 6 months ago #42282

  • booija
  • booija's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 12
tizpardaz wrote:
hello
i want display price without 00
i fix decimal=0 but display price with 00
please help me

To prevent decimals from being shown in the calculation, I just discovered that you have to set the type of the sheet to number
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!