Arrays and selects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    #1

    Arrays and selects

    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
  • Michael Winter

    #2
    Re: Arrays and selects

    On 19 Aug 2004 14:21:42 -0700, Mike <mike.pearce@bi gfathead.com> wrote:
    [color=blue]
    > How do I set this to "disabled":[/color]

    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.

    Comment

    • Grant Wagner

      #3
      Re: Arrays and selects

      Mike wrote:
      [color=blue]
      > 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[/color]

      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.f orm.elements['awards[]'].disabled =
      !this.form.elem ents['awards[]'].disabled;"[color=blue]
      >[/color]

      A shorter form when toggling might be:

      this.form.eleme nts['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 <gwagner@agrico reunited.com>
      comp.lang.javas cript FAQ - http://jibbering.com/faq

      Comment

      Working...