title: How to stop selecting text in textBox and set cursor to last when textBox is focusing by TAB keypress in javascript?
body: <p>I want to stop selecting text in textBox and  set cursor to last when textBox is focusing by TAB keypress. how can I do that? please suggest me. I have tried by googling with following code</p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Test Document&lt;/title&gt;
  &lt;script type="text/javascript"&gt;
  function cursorLast(){
  //    var no = document.getElementById('get').length;
      setCaretPosition(document.getElementById('get'),4);
  
  }
  
  function setCaretPosition(ctrl, pos){
      if(ctrl.setSelectionRange){
          ctrl.focus();
          ctrl.setSelectionRange(pos,pos);
      }
      else if (ctrl.createTextRange) {
          var range = ctrl.createTextRange();
          range.collapse(true);
          range.moveEnd('character', pos);
          range.moveStart('character', pos);
          range.select();
      }
  }
  
  
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
    &lt;form method="get" id="searchform" action="#" &gt;
      &lt;input type="text" onblur="if (this.value == '') {this.value = 'test';}" onfocus="if (this.value == 'test') {this.value = '';}" value="test" name="s" /&gt;
          &lt;br /&gt;&lt;br /&gt;
      &lt;input type="text" value="test" name="s" id="get" onfocus="cursorLast();"/&gt;
    &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This code is not working.</p>
  
  <p>Thanks in advance.</p>