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

164
Vistas
Unable to count form value in javascript

I got a input like this with a numbered value

<input type="radio" id="ja" name="upprepas" value="0">
<input type="radio" id="ja" name="bekanta" value="2">

But i also have like 10 other inputs, I want to count all of the inputed values. So I tried this:

var select = document.querySelector('input[name="upprepas"]:checked');
console.log(select.value);
var selecto = document.querySelector('input[name="bekanta"]:checked');
console.log(selecto.value);
var selector = select.value + selecto.value;
console.log(selector.value);

But selector is always undefined, why is that? I thought that it maybe was a string and not an integer so I tried putting parseInt before select.value but it didn't work.

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

0

What you would need to do is replace var selector = select.value + selecto.value; with var selector = parseInt(select.value) + parseInt(selecto.value); Also use const or let instead of var, it's a best practice ^^

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can always use querySelectorAll to find all of the checked radios, and loop through their values and add them up.

let checked = document.querySelectorAll("input[type='radio']:checked");
let total = 0;
checked.forEach(function(e){
   total += parseInt(e.value);
});

console.log(total)
<input type="radio" name="kreativxt" value="10"> A
<input checked type="radio" name="krexativt" value="1"> V
<input checked type="radio" name="krewativt" value="2"> C

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