title: Readonly input box bug in Internet Explorer
body: <p>I've got a strange bug, well, MSIE does.</p>
  
  <p>Seems it is failing on all major MSIE versions: 6, 7, 8 and 9 (!)</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" &gt;&lt;head&gt;&lt;title&gt;test&lt;/title&gt;
  
    &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript"&gt;
     jQuery(document).ready(function(){
      var test=jQuery('#in');
      test.focus(function(){
       if(test.val()=='empty')test.val('');
       test.attr('readonly',false);
      });
      test.blur(function(){
       if(test.val()=='')test.val('empty');
       test.attr('readonly',true);
      });
     });
    &lt;/script&gt;
  
  &lt;/head&gt;&lt;body&gt;
  
    &lt;input type="text" value="empty" readonly="readonly" id="in"/&gt;
  
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>Let me explain how this system works and what is going wrong.</p>
  
  <p>When the user clicks (focuses) the input box, the input box should be made editable (ie, lose readonly flag). Then, when s/he leaves the input box (ie, blur event) some processing is done (not shown in code) and the input box is made readonly.</p>
  
  <p>This works like a charm in most browsers (firefox, opera, webkit-based), but not any version of IE (including 9 beta).
  The problem is that in IE, the user has to click the input box twice.</p>
  
  <p>At this point, you might ask is the inputbox left readonly the first time?
  No. I tested it, javascript reports that it is editable.</p>
  
  <p>Easy fix, just fire a click event on the input box (to simulate the user's double click behavior), no?
  No, <code>.click()</code> and <code>.focus()</code> both failed. No idea why.</p>
  
  <p><strong>Edit:</strong> Know that the cursor does show up in the text box, at least visibly.</p>
  
  <p><strong>Important:</strong> People, please do at least try the code before answering!</p>