Put a variable in the value of an input

0

I have a variable, for example:

 let exemplo = document.querySelector("#id");

I want to break the value of this variable and put it in value of an input HTML:

<input type="text" valeu="receberia o valor da variável exemplo" />

How can I do this?

    
asked by anonymous 22.01.2018 / 14:57

3 answers

0

You only assign the new value to the value attribute of the object representing your field. Here's an example below:

const novoValor = "Stack Overflow em Português";
const campo = document.getElementById("campo");

campo.value = novoValor;
<input id="campo" value="">
    
22.01.2018 / 15:12
1

Without jquery it would look like this:

var texto = 'abc';
var elemento = document.getElementById('iddoinput');
elemento.value = texto
    
22.01.2018 / 15:13
0

   var exemplo = document.querySelector("#id");
    
    document.querySelector("[name='txtstart']").value = exemplo;
 
    
    <input type="text" required name="txtstart" style="width:150px" value="">
    
22.01.2018 / 15:30