Arrays and selects

Discussion in 'Javascript' started by Mike, Aug 19, 2004.

  1. Mike

    Mike Guest

    Hi all,

    How do I set this to "disabled":

    <select name="awards[]" multiple size="6">
    <option value="1">Award 1</option>
    <option value="2">Award 2</option>
    <option value="3">Award 3</option>
    <option value="4">Award 4</option>
    </select>

    I don't know how many options there will be as they are fed from a DB.

    Thanks very, very much in advance.

    Mike
    Mike, Aug 19, 2004
    #1
    1. Advertising

  2. On 19 Aug 2004 14:21:42 -0700, Mike <> wrote:

    > How do I set this to "disabled":


    When you say, "this", to what are you referring? The whole SELECT element,
    or just some (or all) of the OPTIONS?

    [snip]

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
    Michael Winter, Aug 19, 2004
    #2
    1. Advertising

  3. Mike

    Grant Wagner Guest

    Mike wrote:

    > Hi all,
    >
    > How do I set this to "disabled":
    >
    > <select name="awards[]" multiple size="6">
    > <option value="1">Award 1</option>
    > <option value="2">Award 2</option>
    > <option value="3">Award 3</option>
    > <option value="4">Award 4</option>
    > </select>
    >
    > I don't know how many options there will be as they are fed from a DB.
    >
    > Thanks very, very much in advance.
    >
    > Mike


    document.forms['yourFormName'].elements['awards[]'].disabled = true;

    If you are calling this from someplace on the form, say a button, and you
    already have a reference to the form, you could do something like:

    <input type="button"
    value="Toggle Awards"
    onclick="this.form.elements['awards[]'].disabled =
    !this.form.elements['awards[]'].disabled;"
    >


    A shorter form when toggling might be:

    this.form.elements['awards[]'].disabled ^= true;

    No guarantees it'll work since it turns the result into a number and
    assigning 0 or 1 to disabled may not work - although they should be type
    converted to a boolean - 0 being false, 1 being true. You'll have to test
    it to see if it works (assuming toggling the disabled property is what you
    want to do).

    --
    Grant Wagner <>
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Grant Wagner, Aug 20, 2004
    #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. Dirk Meusel
    Replies:
    1
    Views:
    3,014
    Dirk Meusel
    Aug 19, 2003
  2. Harry
    Replies:
    1
    Views:
    558
    Ather Ali Shaikh
    Jan 17, 2004
  3. Klaus
    Replies:
    1
    Views:
    310
    Joona I Palaste
    Dec 9, 2004
  4. Philipp
    Replies:
    21
    Views:
    1,127
    Philipp
    Jan 20, 2009
  5. Alec Taylor
    Replies:
    5
    Views:
    199
    alex23
    Oct 15, 2011
Loading...

Share This Page