how can I get three text strings to join?

2

I've been trying to merge three different text boxes for a task, but when I wanted to merge the three text boxes into one, I have not managed to do so, any ideas ...?

<!DOCTYPE html>
<html>
<head>
  <title>Ejemplo de JavaScript</title>
  <meta charset="UTF-8">
</head>
<body>


<form name="prueba">
   Primera Frase: <input type="text"id="textA"; />
   Frase final: <input type="text"id="textB"; />
<br>
<br>
   Contenido Medio
<br>
    
   <textarea name="textC" id="textC" cols="50" rows="10">
   </textarea>
<br>
</form>

<script>
var c1=document.getElementById('textA').textContent;
var c2=document.getElementById('textB').textContent;
var t1=document.getElementById('textC').textContent;

</script>
<form name="resultado">
Resultado: 
<br>
<button onclick="document.write(+c1+t1+c2)" id="Boton">Unir</button>
<br>
</form>
</body>
</html>
    
asked by Gabriel 13.09.2018 в 22:11
source

2 answers

0

Create a small code with your source, I hope it works for you:

function unirTexto(){

var c1=document.getElementById('textA').value;
var c2=document.getElementById('textB').value;
var t1=document.getElementById('textC').value;
var resultado= document.getElementById('resultado');
resultado.innerHTML = c1+c2+t1;

}
<form name="prueba">
   Primera Frase: <input type="text"id="textA"; />
   Frase final: <input type="text"id="textB"; />
<br>
<br>
   Contenido Medio
<br>
    
   <textarea name="textC" id="textC" cols="50" rows="10">
   </textarea>
<br>
</form>


Resultado: <span id="resultado"></span>
<br>
<button onclick="unirTexto()" id="Boton">Unir</button>
    
answered by 13.09.2018 / 22:28
source
0

If it is an input or textarea you have to use the value value not the textContent.

Boton.addEventListener("click", function(){

var c1=document.getElementById('textA').value;
var c2=document.getElementById('textB').value;
var t1=document.getElementById('textC').value;
Resultado.innerHTML += c1+c2+t1;
  
})
#Resultado{color:red;}
<form name="prueba">
   Primera Frase: <input type="text"id="textA"; />
   Frase final: <input type="text"id="textB"; />
<br>
<br>
   Contenido Medio
<br>
    
   <textarea name="textC" id="textC" cols="50" rows="10">
   </textarea>
<br>
</form>

<script>

</script>

<p id="Resultado">Resultado: </p> 
<br>
<button id="Boton">Unir</button>
    
answered by 13.09.2018 в 22:25