Find out which type of form element the text field is:
var x = document.getElementById("myText").type;
Click the button to find out which type of form element the text field is.
<!DOCTYPE html> <html> <body> Name: <input type="text" id="myText" value="John"> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/* w ww . ja v a 2 s. com*/ var x = document.getElementById("myText").type; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The type property returns which type of form element a text field is.
For a text field, this property will always return "text".