How do I get what is typed in an HTML text box using JavaScript, as does getText().toString()
in Java?
How do I get what is typed in an HTML text box using JavaScript, as does getText().toString()
in Java?
You can do this. But it has several other forms, it depends on what you want.
function getText() {
input = document.getElementById('campo') //pega o elemento
console.log(input.value); //pega o valor do elemento
}
<input type = "text" value = "texto aqui" id = "campo"/>
<input type = "button" value = "ok" onclick="getText();"/>
Documentation for getElementById()
. The secret is the use of this browser DOM API function. It takes an element of the document being parsed by name. The name is defined by the id
placed in tag HTML.
You can do this too, as I said, depending on the need.
<input type = "text" value = "texto aqui" id = "campo"/>
<input type = "button" value = "ok" onclick="console.log(document.getElementById('campo').value);"/>
You can do something more complex.