Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text input readonly attribute not recognized in IE7?

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

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

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

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

Does anyone have experience with trying to do this with IE7? I do not want to use the disabled attribute as I want the value within the text input field to be submitted with the form.

like image 959
jerome Avatar asked Aug 18 '09 15:08

jerome


People also ask

How do you add a readonly attribute?

Use setAttribute() Method to add the readonly attribute to the form input field using JavaScript. setAttribute() Method: This method adds the defined attribute to an element, and gives it the defined value. If the specified attribute already present, then the value is being set or changed.

How do I make a text field read only?

The readonly attribute is a boolean attribute. When present, it specifies that an input field is read-only. A read-only input field cannot be modified (however, a user can tab to it, highlight it, and copy the text from it).

How do I enable readonly?

Click Review > Restrict Editing. Under Editing restrictions, check Allow only this type of editing in the document, and make sure the list says No changes (Read only). Click Yes, Start Enforcing Protection.

Does readonly input get submitted?

A readonly element is just not editable, but gets sent when the according form submits. A disabled element isn't editable and isn't sent on submit.


1 Answers

Did you try this?

document.getElementById("my_id").readOnly = true;
like image 55
vit Avatar answered Sep 25 '22 13:09

vit