1
How to get what is typed in an HTML text box using Javascript, as well as getText().toString()
in Java?
1
How to get what is typed in an HTML text box using Javascript, as well as getText().toString()
in Java?
1
You can do this. But there are several other ways, depending 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 of 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 set by id
placed in the tag HTML.
Can do so too, as I said, depends on the need.
<input type = "text" value = "texto aqui" id = "campo"/>
<input type = "button" value = "ok" onclick="console.log(document.getElementById('campo').value);"/>
I put in the Github for future reference.
Can do something more complex.
Yes that’s what I was looking for, thank you very much!
Browser other questions tagged javascript html
You are not signed in. Login or sign up in order to post.
Can you explain what you mean by "HTML text box"? You can display the HTML?
– Sergio
An input in my case = <input type="text">
– Drkill32
var texto = document.querySelector('input').value;
<- this reads the value of the first input you find on the page, the method accepts CSS selectors, in this case use a simple:input
. That’s what you’re looking for?– Sergio