Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  Text1: <input type="text" id="text1">
  <br />
  Text2: <input type="text" id="text2">
  <br />
  <br />
  <div><b>COPY the red text below</b> and paste it on Text1:</div>
  <div style="color:red">ABC    DEF</div>
  
  <script>
    function Chr(AsciiNum) {
      return String.fromCharCode(AsciiNum)
    }
    
    function test(pastedText) { 
      var parts = pastedText.split(Chr(9));
      
      document.getElementById("text1").value = parts[0];
      document.getElementById("text2").value = (parts[1] === undefined ? "" : parts[1]);
    }
    
    /**
     * HANDLING PASTE EVENT
     */
    function handlePaste(e) { // Credits to: http://stackoverflow.com/a/6035265/1850609
      var pastedText = undefined;
      if (window.clipboardData && window.clipboardData.getData) { // IE
        pastedText = window.clipboardData.getData('Text');
      } else if (e.clipboardData && e.clipboardData.getData) {
        pastedText = e.clipboardData.getData('text/plain');
      }
      test(pastedText); // Process and handle text...
      return false; // Prevent the default handler from running.
    };
    
    document.getElementById("text1").onpaste = handlePaste;
  </script>
</body>
</html>
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers