title: Deselect text with Javascript
body: <p>I have two input tag with numeric id in a form in one html page. On focus, I would like to set value of the second input from first and second character of the first input. Then I want to deselect the selected text in second input. There is a way to do that?
  I wrote this HTML code:</p>
  
  <pre><code>&lt;label&gt;Num. Fattura:
          &lt;input type="text" name="numfattura1" onkeypress="return event.keyCode != 13" id="1" /&gt;
      &lt;/label&gt;
      &lt;label&gt;Importo:
          &lt;input type="text" name="importo1" onkeypress="return event.keyCode != 13" /&gt;
      &lt;/label&gt;
      &lt;br /&gt;
      &lt;label&gt;Num. Fattura:
          &lt;input type="text" name="numfattura2" onkeypress="return event.keyCode != 13" id="2" onfocus="twoDigits(2)" /&gt;
      &lt;/label&gt;
      &lt;label&gt;Importo:
          &lt;input type="text" name="importo2" onkeypress="return event.keyCode != 13" /&gt;
      &lt;/label&gt;
      &lt;br /&gt;
  </code></pre>
  
  <p>And this javascript function: </p>
  
  <pre><code>function twoDigits(id){
      var previousId = id - 1;
      var prevoiusValue = document.getElementById(previousId).value;
      document.getElementById(id).value = prevoiusValue.substring(0,2);
      document.selection.empty();
      window.getSelection().removeAllRanges()
  }
  </code></pre>
  
  <p>I can't find how to deselect the text that is selected automatically.</p>