Jump to content

Currency Format In Submission Form (Web Form)


Recommended Posts

Is there a way to format a number field in "Submission Form" (Web Form)?

I noticed that one can only do this in resutls page, or whenever the field is a hidden field.

 

Perhaps a JString for the submission form?

 

Thank you as always.

 

Elena

Link to comment
Share on other sites

  • 3 years later...
On 7/14/2014 at 11:31 AM, Elena said:

Is there a way to format a number field in "Submission Form" (Web Form)?

I noticed that one can only do this in resutls page, or whenever the field is a hidden field.

 

Perhaps a JString for the submission form?

 

Thank you as always.

 

Elena

Hi Elena,

You can try this code:
 

 

<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>

 

You just need change the highlited text in red with the exact name of the field.

Link to comment
Share on other sites

  • 2 years later...
On 2/19/2018 at 3:02 PM, Franchiser said:

Hi Elena,

You can try this code:
 

 

<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>

 

You just need change the highlited text in red with the exact name of the field.

 

Hello, I used the code provided. However, there are issues that I have encountered.

First, the format was not enforced onload. You need to click the text field first before the formatting takes place.

Second, the value is being changed to $0.00 on the second click.

 

I don't know if there are other steps that I missed. Can someone help me, please?

Link to comment
Share on other sites

Hi @mrsuave,

I did some minor tweaks and it worked fine on my end. Feel free to test the following code:

 

<script>
var y=document.querySelector("#EditRecordTotalCost"); //change the #EditRecordContractor_Total to the correct element that you need to reference

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>

 

Link to comment
Share on other sites

  • 1 year later...
  • 3 months later...
  • 1 year later...

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
Reply to this topic...

×   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...
×
×
  • Create New...