Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

255
Visualizações
How to do the Multiline Sum in a textbox by using JavaScript

I am trying to sum numbers from 2 text box and the result to a 3rd text box in a PDF Form (Property of text Boxes set to multiline)

Tried the following code but it is not working to add the values and display the results in each row.

var values1 = this.getField("Text6").value.split("\n");
var values2 = this.getField("Text7").value.split("\n");

this.getField("Text8").value = (values1 + values2 );

Unfortunately this is not working.Can someone help me on this?

Expected output below enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You're split()ing a string into arrays, you can't add arrays. You'll need to loop through the arrays to add each number.

Also, the array is an array of strings, because you got it from the value of a textarea, which is going to always return a string. You need to parseInt() the string in order to turn it into a number so it will add the numbers rather than concatenate a string.

function getField(id) {
  return document.getElementById(id);
}

var values1 = this.getField("Text6").value.split("\n");
var values2 = this.getField("Text7").value.split("\n");


for(i = 0; i < values1.length; i++) {
  this.getField("txtSums").value += (parseInt(values1[i]) + parseInt(values2[i])) + "\n";
}
<textarea id="Text6">1
2
3</textarea>
<br />
<br />
<textarea id="Text7">4
5
6</textarea>

<br /><br />

sums:<br />
<textarea id="txtSums"></textarea>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda