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 2 of 2
  1. #1
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts

    Make a form element read only only when. . .

    Hello -


    I know I can make a field permenently read only with -

    onfocus='this.blur();'

    but how can I make a form element read only when a certain condition is met? ie. if one field is checked or filled out make the other field read only?

    TIA,
    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Ha! Staring blankley at your post really does help.

    Code:
    function readOnly(obj)
    {
    if(x!=y)
    {
    document.getElementById(obj).blur()
    }
    
    <input type="text" id="txt1" onfocus="readOnly('txt1')">
    This will work - but is there not a way that I could set this up and just call the function like this: readOnly(this); So that It knows I am refering to the focused object? As I have it now by passing "this" - "this" would refer to the function not the object correct?

    I think I need to create an object or somthing but I'm just not there yet.

    Thanks Again,
    Basscyst
    Helping to build a bigger box. - Adam Matthews


  •  

    Posting Permissions

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