What about formatting a asp.net textbox? Example Below:
var txtJeff = document.getElementById('<%= TextBox1.ClientID %>');
I've figured out how to format the label i'm returning in a hidden field but returning as the user enters in the textbox or leaves a textbox(onblur) is there a way I can call something to format the number for the user?
spsubaseball
Member
20 Points
31 Posts
Insert a comma after thousnd (Ex: 1,000 not 1000)
May 01, 2012 06:00 PM|LINK
How can I format my javascript function so that the textbox puts a comma after thousands mark after a number is entered in the textbox?
Here is my code below:
function Calculate() { var txthoa = document.getElementById('<%= txtHOA.ClientID %>'); var txtrent = document.getElementById('<%= txtRental.ClientID %>'); var txtcost = document.getElementById('<%= txtRehab.ClientID %>'); var txttitle = document.getElementById('<%= txtTitleAmt.ClientID %>'); var lblCapRate = document.getElementById('<%= lblCapRate.ClientID %>'); var lbltwenty = document.getElementById('<%= lbltwenty.ClientID %>'); var lbleighteen = document.getElementById('<%= lbleighteen.ClientID %>'); var lblsixteen = document.getElementById('<%= lblsixteen.ClientID %>'); if (txthoa.value == "") { txthoa.value = "0.00"; } if (txtrent.value == "") { txtrent.value = "0.00"; } if (txtcost.value == "") { txtcost.value = "0.00"; } if (txttitle.value == "") { txttitle.value = "0.00"; } var hoa = parseFloat(txthoa.value); var rent = parseFloat(txtrent.value); var cost = parseFloat(txtcost.value); var title = parseFloat(txttitle.value); if (txthoa.value != "" && txtrent.value != "" && txtcost.value != "" && txttitle.value != "") { var sixteen; var twenty; var eighteen; twenty = (((rent * 12) - 600 - 500 - (rent * 12 * .06) - 800 - 300 - hoa - title) / .2) - cost - (cost * .165); eighteen = (((rent * 12) - 600 - 500 - (rent * 12 * .06) - 800 - 300 - hoa - title) / .18) - cost - (cost * .165); sixteen = (((rent * 12) - 600 - 500 - (rent * 12 * .06) - 800 - 300 - hoa - title) / .16) - cost - (cost * .165); lblsixteen.innerHTML = '$' + parseFloat(sixteen).toFixed(0); lbleighteen.innerHTML = '$' + parseFloat(eighteen).toFixed(0); lbltwenty.innerHTML = '$' + parseFloat(twenty).toFixed(0); document.getElementById('<%=HiddenField2.ClientID %>').value = lblsixteen.innerHTML; document.getElementById('<%=HiddenField3.ClientID %>').value = lbleighteen.innerHTML; document.getElementById('<%=HiddenField4.ClientID %>').value = lbltwenty.innerHTML; } }Any suggestions?
protienshow
Member
716 Points
146 Posts
Re: Insert a comma after thousnd (Ex: 1,000 not 1000)
May 01, 2012 09:00 PM|LINK
Check this post
http://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-money-in-javascript
Number.prototype.formatMoney = function(c, d, t){ var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0; return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); }; (123456789.12345).formatMoney(2, '.', ',');Create Dashboard In MVC
asteranup
All-Star
30184 Points
4906 Posts
Re: Insert a comma after thousnd (Ex: 1,000 not 1000)
May 02, 2012 07:31 AM|LINK
Hi,
You can try this plugin-
http://josscrowcroft.github.com/accounting.js/
http://www.josscrowcroft.com/2011/code/format-unformat-money-currency-javascript/
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
spsubaseball
Member
20 Points
31 Posts
Re: Insert a comma after thousnd (Ex: 1,000 not 1000)
May 03, 2012 03:01 PM|LINK
What about formatting a asp.net textbox? Example Below:
var txtJeff = document.getElementById('<%= TextBox1.ClientID %>');
I've figured out how to format the label i'm returning in a hidden field but returning as the user enters in the textbox or leaves a textbox(onblur) is there a way I can call something to format the number for the user?