Jump to content
  • 0

Currency field input mask


Gunnar360c
 Share

Question

4 answers to this question

Recommended Posts

  • 0

Hello @Gunnar360c,

Thanks to @Franchiser for providing the code as it works for me. The following code was just added to the Header/Footer section of my Submission Form DataPage:

=============================================================================================

<script>
var y=document.getElementById("InsertRecordCurrency");
y.onblur = function() {myFunction()};

function myFunction() {
var x = y.value;
y.value=CommaFormatted(CurrencyFormatted(y.value));

function CurrencyFormatted(amount)
{
var i = parseFloat(amount);
if(isNaN(i)) { i = 0.00; }
var minus = '';
if(i < 0) { minus = '-'; }
i = Math.abs(i);
i = parseInt((i + .005) * 100);
i = i / 100;
s = new String(i);
if(s.indexOf('.') < 0) { s += '.00'; }
if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
s = minus + s;
return s;
}

function CommaFormatted(amount)
{
var delimiter = ","; // replace comma if desired
var a = amount.split('.',2)
var d = a[1];
var i = parseInt(a[0]);
if(isNaN(i)) { return ''; }
var minus = '';
if(i < 0) { minus = '-'; }
i = Math.abs(i);
var n = new String(i);
var a = [];
while(n.length > 3)
{
var nn = n.substr(n.length-3);
a.unshift(nn);
n = n.substr(0,n.length-3);
}
if(n.length > 0) { a.unshift(n); }
n = a.join(delimiter);
if(d.length < 1) { amount = n; }
else { amount = n + '.' + d; }
amount = minus + amount;
return "$" + amount;
}
}
</script>
=============================================================================================

According to him, you just need change the highlighted text in red with the exact name of your currency field. 

I hope this works for you as well!

Link to comment
Share on other sites

  • 0

Hi! Just an update on this, there is another solution or workaround that might help you when it comes to formatting text or editable fields in currency. This is by using a JavaScript library that creates an input mask. For more information, you may check these links:
- https://github.com/RobinHerbots/Inputmask
- https://robinherbots.github.io/Inputmask/

As a test, here is a sample code when applied in a DataPage.

Header:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/5.0.7/jquery.inputmask.min.js"></script>

Footer:

<script>

document.addEventListener('DataPageReady', function (event) {

$("#EditRecordFIELDNAME").inputmask({ alias : "currency", prefix: '$ ' });
$("#EditRecordFIELDNAME").inputmask({ alias : "currency", prefix: '$ ' });

});

</script>

Hope it helps!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...