Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>JS Bin</title>
  </head>
  <body>
    
    <div>
      <input type="text" value="javascript is awesome">
    </div>
    
    
    <button>Read Value of Text Field using .val()</button>
    <script src="https://code.jquery.com/jquery-3.1.0.js"></script>
  </body>
</html>
 
$(function(){
  
  $("button").click(readTextField);
  
  function readTextField() {
    // use .val() with nothing inside the parentheses to READ the value in the text field
    // and store it in a variable called textFieldValue
    let textFieldValue = $("input").val();
    
    // print out the value in an alert
    alert(textFieldValue);
  }
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x