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.
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.
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).
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.
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.
Did you try this?
document.getElementById("my_id").readOnly = true;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With