Skip welcome & menu and move to editor
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>
  <textarea id="myText" rows="4" cols="50" onkeypress="">The rain in Spain falls mainly on the plains.</textarea>
  <br>
  <button onclick="updateText()">Update</button>
</body>
</html>
 
function updateText(e) {
  var ele = document.getElementById('myText');
  var newVal = 'Old McDonald had a farm.\n';
  ele.value = newVal;
  ele.focus();
  // To update cursor position to recently added character in textBox
  ele.setSelectionRange(newVal.length, newVal.length);
}
Output

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

Dismiss x
public
Bin info
chris0pro
0viewers