Readonly input box bug in Internet Explorer

I've got a strange bug, well, MSIE does.

Seems it is failing on all major MSIE versions: 6, 7, 8 and 9 (!)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" xml:lang="en-gb" lang="en-gb" ><head><title>test</title>

  <script type="text/javascript" src=""></script>
  <script type="text/javascript">
    var test=jQuery('#in');


  <input type="text" value="empty" readonly="readonly" id="in"/>


Let me explain how this system works and what is going wrong.

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.

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.

At this point, you might ask is the inputbox left readonly the first time? No. I tested it, javascript reports that it is editable.

Easy fix, just fire a click event on the input box (to simulate the user's double click behavior), no? No, .click() and .focus() both failed. No idea why.

Edit: Know that the cursor does show up in the text box, at least visibly.

Important: People, please do at least try the code before answering!



I wouldn't say it's a bug. If you change the value, you also remove the current textRange.

Try , it should give the cursor back to the input.


will result in a loop that will end in an "not enough memory"-error.


I believe that readonly should be readOnly. Seems weird you would toggle this property. You can also try to remove it

jQuery("#foo").removeAttr("readOnly"); //.removeAttr("readonly");

try this ive just tried that and it works:

<input type="text" value="empty" id="in" readonly/>


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.