Q: how to set the readonly attribute to false (IE and Moz)

Discussion in 'Javascript' started by Fred K., Dec 9, 2003.

  1. Fred K.

    Fred K. Guest

    Hi,

    I have form text fields that have the attribute readonly. I wish to
    use a javascript (invoked by a button on my page) to erase the values
    and set
    the readonly attribute to false. How do I do this?

    Here's what I have that is not working with respect to setting
    readonly to false:
    function nsfields ( bDefaults ) {

    if ( bDefaults == "Yes" ) {
    // insert the default values in the fields
    document.form1.ns1_hostname.value = 'foo.foobar.com';
    document.form1.ns1_hostname.readonly = 'readonly';

    } else {
    // Blank the fields
    document.form1.ns1_hostname.value = '';
    document.form1.ns1_hostname.readonly = false;
    }
    }
    Fred K., Dec 9, 2003
    #1
    1. Advertising

  2. Re: how to set the readonly attribute to false (IE and Moz)

    "Fred K." <> wrote:

    > Here's what I have that is not working with respect to setting
    > readonly to false:


    <snip>

    > document.form1.ns1_hostname.readonly = false;


    Use: document.form1.ns1_hostname.readOnly = false;
    ^
    Note the case.

    And, BTW, it is safer to write:

    document.forms["form1"].elements["ns1_hostname"]
    Vjekoslav Begovic, Dec 9, 2003
    #2
    1. Advertising

  3. Fred K.

    DU Guest

    Fred K. wrote:

    > Hi,
    >
    > I have form text fields that have the attribute readonly. I wish to
    > use a javascript (invoked by a button on my page) to erase the values
    > and set
    > the readonly attribute to false. How do I do this?
    >
    > Here's what I have that is not working with respect to setting
    > readonly to false:
    > function nsfields ( bDefaults ) {
    >
    > if ( bDefaults == "Yes" ) {
    > // insert the default values in the fields
    > document.form1.ns1_hostname.value = 'foo.foobar.com';
    > document.form1.ns1_hostname.readonly = 'readonly';
    >
    > } else {
    > // Blank the fields
    > document.form1.ns1_hostname.value = '';
    > document.form1.ns1_hostname.readonly = false;
    > }
    > }


    http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-88461592
    but
    http://www.robinlionheart.com/stds/html4/results.xhtml#readonly_text_only

    DU
    DU, Dec 9, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. André
    Replies:
    3
    Views:
    1,586
  2. Jonathan Hyatt
    Replies:
    1
    Views:
    1,914
    Jonathan Hyatt
    Jun 8, 2004
  3. trans.  (T. Onoma)
    Replies:
    0
    Views:
    152
    trans. (T. Onoma)
    Sep 25, 2004
  4. trans.  (T. Onoma)
    Replies:
    1
    Views:
    167
    David A. Black
    Sep 25, 2004
  5. Aaron Gray
    Replies:
    4
    Views:
    128
    Aaron Gray
    Jan 4, 2007
Loading...

Share This Page