Read text input attribute not recognized in IE7?

I set readonly = "readonly" (in other words, true) via javascript:

document.getElementById("my_id").setAttribute("readonly", "readonly"); 

This has the intended effect (making the field no longer editable, but its contents are presented in the form) in FF, Safari and Chrome, but not for IE7. In IE7, I can still change the contents of the text input field.

I also tried the setting ("readonly", "true"), which works in all three other browsers that I am testing, but IE7 also ignores.

Does anyone have any experience with IE7? I do not want to use the disabled attribute, since I want the value in the text input field to be submitted with the form.

+4
source share
4 answers

Have you tried this?

 document.getElementById("my_id").readOnly = true; 
+13
source

to try:

 document.getElementById("my_Id").setAttribute("readOnly","readonly") 

this is readOnly , O is capital!

+2
source
 <script type="text/javascript"> function blah(txt) { var text = document.getElementById(txt).value; if(text.length > 4 && document.getElementById('chk').checked == false) { // ********* NOT WORKING WITH IE *************** // //document.getElementById("ta").setAttribute('readOnly','readonly'); //document.getElementById("ta").readOnly="readOnly"; // ******** --- **********// //document.getElementById("ta").disabled = true; // for disable textArea document.getElementById("ta").blur(); // comment this when above line is uncommented or visa-versa document.getElementById('chkBox').style.display = "block"; } } function unable() { // document.getElementById("ta").disabled = false; // to unable textArea -- uncomment when disabling is used or visa-versa document.getElementById('ta').focus(); document.getElementById('chkBox').style.display = "none"; } </script> <textarea id="ta" onkeydown="blah('ta')" ></textarea> <div id="chkBox" style="display:none"><label> Please check this to continue....</label><input type="checkbox" id="chk" onclick="unable()"></div> 
+2
source

Or try:

document.getElementById("my_id").setAttribute("readOnly", true);

Please note, as pointed out by @TheVillageIdiot, O in readOnly is TOP . This should work from IE7 to IE11.

0
source

All Articles