Concatenate two variables obtained by the getElementByID method

0

I have the following problem:

I need to concatenate two objects obtained by the method mentioned above

 var textApellido   = document.getElementById('textApellido');
 var textNombre     = document.getElementById('textNombre'); 
 var resultado = textNombre + textApellido;

Getting the result

  

Can not read property 'toString' of undefined

    
asked by jecorrales 03.11.2017 в 21:29
source

1 answer

3

That happens to you because you are capturing the element but not its value, to capture the value you must do the following:

1. If it is a form element

var textApellido   = document.getElementById('textApellido').value;
var textNombre     = document.getElementById('textNombre').value; 

2. If it is a div or any other element that is not in form

var textApellido   = document.getElementById('textApellido').innerHTML;
var textNombre     = document.getElementById('textNombre').innerHTML; 
    
answered by 03.11.2017 / 21:30
source