0

tengo un problema al hacer un appendChild al input con el resultado de una operacion que toma 2 inputs.

<input id="firstNumber" type="text" value="" /> + <input id="secondNumber" type="text" value="" /> = <input id="resultNumber" type="text" value="" />
<input type="button" value="Calculate" onclick="calculateSumListener();" />

para esto tengo la siguiente funcion.

function calculateSumListener() {
//Return the value of the input #firstNumber
var stringA = document.getElementById('firstNumber').value; 
//Return the value of the input #secondNumber
var stringB = document.getElementById('secondNumber').value; 

//your code goes here
let result = document.getElementById('resultNumber');

// reasignar
let value = parseInt(stringA) + parseInt(stringB);
result.appendChild(value); }

El error que presenta en Argument 1 of Node.appendChild is not an object.

1 respuesta 1

3

La función appendChild permite "insertar" un elemento HTML dentro de otro, es decir que el argumento que le tienes que dar debe ser un HTMLElement, en tu ejemplo el argumento es de tipo number.

En su lugar usa:

result.value = value;

Espero te sirva.

1
  • eres un genio! gracias!!! solucionado
    – Richi
    el 25 mar. 2019 a las 16:56

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.