Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Can't Unset readonly attribute of a textbox

    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.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    use DOM
    Code:
    var obj =document.getElementById('Papername');
    if(PaperName=='Examiner')
    {
    obj.setAttribute('readOnly','readonly');
    }
    else
    {
    obj.removeAttribute('readOnly');
    }
    Last edited by Kor; 11-03-2006 at 12:09 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Works like a dream. THANK YOU!

  • #4
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by deanes02 View Post
    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".


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •