I’m trying to do a text input, and what I type into it I want to play within a variable?

Asked

Viewed 33 times

1

<input id="a_input" type="text" >

var b = Document.getElementById('a_input'). innerText = '';

//There are ways you can return to me what I typed in the Alert input to make it easier ??

1 answer

0


Do not use innerText, use value:

var b = document.getElementById('a_input').value;
alert(b);

We use innerText for objects that may have content in html, as div and span, to get the text content, and if you want the html content, innerHTML

  • bro forget to say from the button rs that when I click on it the value goes pro Alert

  • then you need to add a Listener to follow the event "onfocus", which happens when the field receives the focus, that is, after clicking on it or navagar on it by TAB, and can do, in the simplest way to understand, so: <input id="a_input" type="text" onfocus="alert(this.value)" >

Browser other questions tagged

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