otnj2ee
01-22-2009, 01:15 AM
There are two ways for me to make a input field readonly:
1)hardcoding:
In a JSP, I use <input type="text" id="test" readonly="readonly" value="1234abc" />
The field will become readonly--I can not edit the text in the field. This is what I wanted.
2) Dynamical:
But sometimes I need to achieve this at the runtime/dynamically:
<input type="text" value="1234abc" />
Now in the javascript:
document.getElementById("test").readonly = true;
The field will display as readonly. However, I can actually highlight the text, delete and edit it.
Why so and how can I solve this problem?
Thanks
Scott
1)hardcoding:
In a JSP, I use <input type="text" id="test" readonly="readonly" value="1234abc" />
The field will become readonly--I can not edit the text in the field. This is what I wanted.
2) Dynamical:
But sometimes I need to achieve this at the runtime/dynamically:
<input type="text" value="1234abc" />
Now in the javascript:
document.getElementById("test").readonly = true;
The field will display as readonly. However, I can actually highlight the text, delete and edit it.
Why so and how can I solve this problem?
Thanks
Scott