I find that document.getElementById('textbox-id').readOnly=true
sometimes doesn't work reliably.
Instead, try:
document.getElementById('textbox-id').setAttribute('readonly', 'readonly')
and
document.getElementById('textbox-id').removeAttribute('readonly')
.
A little verbose but it seems to be dependable.