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>

1

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

This may Helps:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.