JavaScript Example | Get the Value of a Text Input

This javascript example will introduce how to get the value of a text input in html.

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the Document</title>
  </head>
  <body>
    <input type="text" placeholder="Type " id="inputId">
    <button type="button" onclick="getInputValue();">Get Value</button>
    <script>
      function getInputValue() {
        // Selecting the input element and get its value 
        let inputVal = document.getElementById("inputId").value;
        // Displaying the value
        alert(inputVal);
      }
    </script>
  </body>
</html>

The key point is: document.getElementById().