...

View Full Version : Can't Unset readonly attribute of a textbox



deanes02
11-03-2006, 11:35 AM
i need to make a textbox in html readonly and not readonly based on certain choices

if(PaperName=='Examiner')
{
document.getElementById('Papername').readOnly="True";
}
else
{
document.getElementById('Papername').readOnly="False";
}

The problem is that once the readonly attribute is set to true it does not seem to unset to false.

Kor
11-03-2006, 12:06 PM
use DOM


var obj =document.getElementById('Papername');
if(PaperName=='Examiner')
{
obj.setAttribute('readOnly','readonly');
}
else
{
obj.removeAttribute('readOnly');
}

deanes02
11-03-2006, 12:12 PM
Works like a dream. THANK YOU!

Arty Effem
11-03-2006, 03:41 PM
i need to make a textbox in html readonly and not readonly based on certain choices

if(PaperName=='Examiner')
{
document.getElementById('Papername').readOnly="True";
}
else
{
document.getElementById('Papername').readOnly="False";
}

The problem is that once the readonly attribute is set to true it does not seem to unset to false.The reason this doesn't work is because the property must be passed a boolean (true or false) not a string. The string "True" evaluates to true but so does the string "False".



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum