SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Hybrid View

  1. #1
    SitePoint Zealot ant1832's Avatar
    Join Date
    Apr 2002
    Location
    Tucson, AZ
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Disabled field value

    I have a value in a disabled field...when I send the form, the value is not sent. If I set disabled=false then it works. Is there anyway that I could make a field disabled so the person can still see the data in the field but not edit it and also submit the disabled value?

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't really DISABLE it and SUBMIT it.

    You have three options:

    1) Leave it as a normal field, but whenever the user focuses it - blur it ( onfocus='blur();' )

    2) onsubmit of the form scan for disabled fields and enable them.

    3) If you're only looking at a few inputs which will be disabled - hard code their names to be enabled onsubmit.

    btw - not DEFINATE on this - but you might need the onbeforesubmit - but i doubt it.
    Just thought i'd mention it incase you find that you change their state onsubmit and the browser doesn't take any notice.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Location
    Penns Woods
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Also...

    If you want the text box to have the Appearance of being disabled, besides adding onFocus='blur();' you can change the background color of the text box and the color of the text using Style. Something like this...

    <style>
    #dis { color:#9d9d9d; background-color:#d8d8d8 }
    </style>
    </head>

    <body>
    <form>
    <input type="text" id="dis" value="Disabled" onFocus="this.blur()" length="30" />
    </form>
    // PS! My brain just hit a bad sector...

  4. #4
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use readonly, that will prevent modifications to it, and also will allow it to be submitted etc

  5. #5
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Andrew's solution is by far the best.

    Good call mate

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  6. #6
    SitePoint Zealot ant1832's Avatar
    Join Date
    Apr 2002
    Location
    Tucson, AZ
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help everyone...just one question though, how do I apply the readonly attribute? I was using this "document.forms.myForm._fid_14.disabled=true" to make it disabled. What's the correct format to mark it readonly w/ javascript?

  7. #7
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try

    document.all[obj].readonly = true;
    document.all[obj].readonly = false;
    document.getElementById['obj'].readonly = true;
    document.getElementById['obj'].readonly = false

    etc

  8. #8
    SitePoint Zealot ant1832's Avatar
    Join Date
    Apr 2002
    Location
    Tucson, AZ
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry to be such a pest andrew, but that doesn't seem to work. Maybe I'm still formatting it incorrectly. My field's name and id are both set to '_fid_17'. I tried using document.getElementById['_fid_17'].readonly = true;, but I get an error in IE stating that document.getElementById.fid_17 is not an object or is null. What am I doing wrong???

  9. #9
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to be a pain too:
    1) The property is actually .readOnly (I hate case sensitivity too)
    2) It is only supported in IE4+

    I suggest .disabled or using the blur technique.
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  10. #10
    SitePoint Zealot ant1832's Avatar
    Join Date
    Apr 2002
    Location
    Tucson, AZ
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah I just figured out the case sensitivity thing right b4 u posted. And now it seems to work except one thing. When the form loads the focus in on a read only field. As soon as you leave the field you can't go back and edit it, but if you edit the field while focus is on it you can change the value...is there anyway to stop this?

    About using disable...i was using that method, but then the values aren't submitted. About using onBlur...how would I use that dynamically? Meaning how can I set onBlur only if certain conditions are true.

  11. #11
    SitePoint Zealot ant1832's Avatar
    Join Date
    Apr 2002
    Location
    Tucson, AZ
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok nevermind...I just set the 1st tab index to a hidden field. Now the readonly fields are really readonly. Thanks for all of your help everyone, I don't know what I would do w/out sitepoint.

  12. #12
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe, it's not s/p it's the people that make it what it is. Good thing it brings everyone together, otherwise i'd never of learnt ne of this stuff.


Bookmarks

Posting Permissions

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