Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
How to use join function to sum 2 fields in JavaScript

Can someone help me to sum the 2 fields and display the results in one box by using JavaScript.

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

for(i = 0; i < values1.length  ; i++)
{
values1[i] =  parseInt(values1[i]) + "\n";
values2[i] =  parseInt(values2[i]) + "\n";


this.getField("Text8").value = (values1[i]+values2[i]).join("") ;
}   

I am getting the following error: TypeError: (values1 + values2).join is not a function

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can't join like that, the join method can only be applied on an array.

You can do this:

this.getField("Text8").value = [values1[i], values2[i]].join("");

But a better way:

this.getField("Text8").value = `${values1[i]}${values2[i]}`;

EDIT:

If you want to do a sum, you can simply do this:

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

If you have string instead of a int as values, then you need to cast their values before:

this.getField("Text8").value = parseInt(values1[i]) + parseInt(values2[i]);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda