title: How to convert text to binary using javascript
body: <p>I want to make a text to binary converter. For example if someone types in 'Hello' it would return <code>0100100001100101011011000110110001101111</code> How can I do this? I have tried this but something is wrong:</p>
  
  <pre><code>function convertBinary() {
      var output = document.getElementById("outputBinary");
      var input = document.getElementById("inputBinary").value;
      output.value = "";
      for (i=0; i &lt; input.length; i++) {
          output.value +=input[i].charCodeAt(0).toString(2);
      }
  }
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Binary Converter&lt;/title&gt;
  &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  function convertBinary() {
      var output = document.getElementById("outputBinary");
      var input = document.getElementById("inputBinary").value;
      output.value = "";
      for (i=0; i &lt; input.length; i++) {
          output.value +=input[i].charCodeAt(0).toString(2);
      }
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;center&gt;
  &lt;div class="container"&gt;
      &lt;span class="main"&gt;Binary Converter&lt;/span&gt;&lt;br&gt;
      &lt;input type="text" onKeyUp="convertBinary()" id="inputBinary" class="inputBinary" placeholder="Enter Text"&gt;&lt;br&gt;
      &lt;input type="text" id="outputBinary" class="outputBinary" readonly&gt;
  &lt;/div&gt;
  &lt;/center&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Any help will be greatly appreciated. Thanks, Omar.</p>