Fill text-area field while input information is entered

Asked

Viewed 456 times

1

I have a text-area and a input, wanted that when typing some information in the input it already fills in the text-area. I tried the event onchange, but from what I’ve noticed it’s only fired when it leaves the field, there’s some input event that does that?

<input onchange="FuncaoTeste();" type="text" class="form-control" id="iptDetalhes">

2 answers

5

Here is an example with the onkeyup (as @Leonardo-Getulio said):

HTML

<textarea id="iptDetalhesCopia"></textarea>
<input onkeyup="FuncaoTeste( this.value )" type="text" class="form-control" id="iptDetalhes" placeholder="Digite aqui">

JS

function FuncaoTeste( e ) {
    document.getElementById( 'iptDetalhesCopia' ).value = e;
}

https://jsfiddle.net/xtkfrbj2/

4


Just complementing Mark’s response ,the event onChange will only reflect the value entered in input when it receives the event of Blur, that is, lose focus, already with keyboard events like keyup, or input the moment something is entered in the input, these values will be automatically passed to the textarea:

let valor = document.getElementById('iptDetalhes');

valor.addEventListener('input', () => document.getElementById('textarea').textContent = valor.value)
<input type="text" class="form-control" id="iptDetalhes"> <br><br>
<textarea id="textarea" cols="22"></textarea>

  • 1

    I got it, it worked with the omninput event. Thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.