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="">
    </div>
    
    
    <button>Write 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() {
    let newTextFieldValue = "Barney the Purple Dinosaur";
    // use .val(<new value>) with a string inside the parentheses to WRITE the value in the text field
    // this will fill in the text field with value stored in the variable named newTextFieldValue
    $("input").val(newTextFieldValue);
  }
});
Output

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

Dismiss x