Elena Posted July 14, 2014 Report Share Posted July 14, 2014 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 Quote Link to comment Share on other sites More sharing options...
Jan Posted July 17, 2014 Report Share Posted July 17, 2014 Hello Elena, As far as I know, you can define format of input number in your Localization. But it will be applied to all numbers, not only to one field. Sorry, what formatting do you want to use? Quote Link to comment Share on other sites More sharing options...
Jan Posted July 18, 2014 Report Share Posted July 18, 2014 Hello again, It seems, in this topic there is an answer that can helps. Quote Link to comment Share on other sites More sharing options...
Franchiser Posted February 19, 2018 Report Share Posted February 19, 2018 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. Foodspark 1 Quote Link to comment Share on other sites More sharing options...
mrsuave Posted October 14, 2020 Report Share Posted October 14, 2020 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? Quote Link to comment Share on other sites More sharing options...
JolliBeng Posted October 14, 2020 Report Share Posted October 14, 2020 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> Quote Link to comment Share on other sites More sharing options...
Flowers4Algernon Posted March 19, 2022 Report Share Posted March 19, 2022 Hi, just wanted to share this related post that may be helpful as well Quote Link to comment Share on other sites More sharing options...
Kurumi Posted June 24, 2022 Report Share Posted June 24, 2022 Hi - you may also check this updated post: Quote Link to comment Share on other sites More sharing options...
futurist Posted November 20, 2023 Report Share Posted November 20, 2023 You may refer to this Forum post to validate data entry to make sure that they follow this format: www.websitenamehere.com Foodspark 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.