How to pass data from an input to javascript and then display it

0

I have this code to fetch the value of my input

<Script>

 var name = document.getElementById("name").value;

I would like to know how to introduce it in a spam for example

    
asked by anonymous 19.03.2018 / 16:00

1 answer

3

Here's a simple example using just javascript.

var mostrarNome = function (){
  var exibicao = document.getElementById("exibir");
  var nome = document.getElementById("nome").value;
  
  exibicao.innerText = nome;  
  
}
<input type="text" id="nome" />
<br />
<button type="button" onclick="mostrarNome()">Exibir</button>
<br />
<span id="exibir"></span>
    
19.03.2018 / 16:26