Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML textarea doesn't update while typing in Chrome

On a page with the following code, the textarea doesn't update with text that I type, until I click off of it. Why?

<html>

<head>
  <style>
    #canvas {
      float: left;
    }
  </style>
  <script>
    window.onload = function() {
      var canvas = document.getElementById('canvas');
      var ctx = canvas.getContext('2d');
      ctx.translate(0, 0);
    }
  </script>
</head>

<body>
  <canvas id="canvas" width=439></canvas>
  <textarea></textarea>
</body>

</html>

I've discovered that the textarea will update properly if I do any one of the following:

  • Change the width of the canvas to 438 or less
  • Remove ctx.translate(0,0);
  • Remove float: left;

This only happens in Chrome, I can't reproduce in Firefox. I'm running Chrome 39.0.2171.95 and Firefox 34.0.5

like image 737
Robz Avatar asked Apr 13 '26 08:04

Robz


1 Answers

That is really odd behavior. You can fix it by adding relative positioning to the textarea:

<html>

<head>
  <style>
    #canvas {
      float: left;
    }
    textarea {
      position: relative;
    }
  </style>
  <script>
    window.onload = function() {
      var canvas = document.getElementById('canvas');
      var ctx = canvas.getContext('2d');
      ctx.translate(0, 0);
    }
  </script>
</head>

<body>
  <canvas id="canvas" width=439></canvas>
  <textarea></textarea>
</body>

</html>
like image 61
Rick Hitchcock Avatar answered Apr 16 '26 01:04

Rick Hitchcock