#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    236
    Rep Power
    12

    Javascript snag with disabled form fields.


    Hi all, I have disabed a text box with the...

    <... disabled="disabled"> option, however if I try and do a javascript onclick on the input field, it no longer responds.

    It seems disabling a form field stops it from being accessed via the typical js methods.

    Is there a work around for this? Please help.

    Taz
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2003
    Posts
    1,014
    Rep Power
    15
    Well, if you disable an input button, it no longer can get focus and the value is not sent along when submitting the form... That's what disabling a form element is supposed to do.

    If you don't like it:
    1. make it readonly instead of disabled (but then the value is always sent)
    2. create something else that can (re-)enable the button.

    Hope this helps,
    Jeroen
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    236
    Rep Power
    12
    Thanks for the reply.

    How do I go about making it read only??

    Taz
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2003
    Posts
    1,014
    Rep Power
    15
    Code:
    <input type="text" id="mytext" readonly="readonly" value="some value" onclick="alert('readonly field')">
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    236
    Rep Power
    12
    is the readonly attribute something from HTML3.2 or later?

    How well will older browsers support it?

    Cheers
    Taz

IMN logo majestic logo threadwatch logo seochat tools logo