0

The case goes like this I have 4 textbox the dynamic is the following textbox1 + textbox2 + textbox 3 = textbox4. When entering the numbers in the textbox, I would like to give it the following format:

NOW: 123456789 WANTED: 123,456,789.00

function agregar_numero() {

  var TextBox1 = parseInt(document.getElementById("txtremubruta").value);
  var TextBox2 = parseInt(document.getElementById("txtotrosingresos").value);
  var TextBox3 = parseInt(document.getElementById("txtremubrutamensual").value);
  var result = TextBox1 + TextBox2 + TextBox3;

  document.getElementById("TxtInfoPatriTotal").value = result;
}
<form runat="server">
  <asp:TextBox ID="txtremubruta" runat="server" CssClass="TextBoxBorder" Width="70px" onkeyup="agregar_numero()"></asp:TextBox>
  <asp:TextBox ID="txtotrosingresos" runat="server" CssClass="TextBoxBorder" Width="70px" onkeyup="agregar_numero()"></asp:TextBox>
  <asp:TextBox ID="txtremubrutamensual" runat="server" CssClass="TextBoxBorder" Width="70px" onkeyup="agregar_numero()"></asp:TextBox>
  <br> Total
  <br>
  <asp:TextBox ID="TxtInfoPatriTotal" runat="server" CssClass="TextBoxBorder" Width="70px"></asp:TextBox>

</form>
Kas Elvirov
  • 7,394
  • 4
  • 40
  • 62
Curious
  • 111
  • 1
  • 1
  • 10
  • 4
    Possible duplicate of [How to print a number with commas as thousands separators in JavaScript](https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript) – 31piy Jul 31 '18 at 06:21

2 Answers2

3

You can simply use toLocaleString method here's the code:

var num = 123456789;
num.toLocaleString(undefined, {minimumFractionDigits: 2}) // "123,456,789.00"

Hope it helps.

Zeeshan Tariq
  • 604
  • 5
  • 10
1

This may Helps:

function addComma(txt) {
txt.value = txt.value.replace(",", "").replace(/(\d+)(\d{3})/, "$1,$2");
}