Question about SELECT element

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

    Question about SELECT element

    Hi, all

    On a SELECT object, I try to set it's value with one of the value of
    options, such as selectObj.value ="whatever". Sometime it works while
    sometimes it won't work at all , using IE6. When we want to set a value to
    the SELECT object, have to know it's option index first. Then set
    selectedIndex to that index. Is there a quick way to set a select value with
    a known value?

    Jack


  • Matt Kruse

    #2
    Re: Question about SELECT element

    datactrl wrote:[color=blue]
    > Is there a quick way to set a
    > select value with a known value?[/color]

    There is no "quick" way. You need to cycle through all the options, find the
    option (or options) that have a value matching yours, and mark them as
    selected.

    You can hide this all in a general function, though, which I find to be most
    convenient.
    Then, using functions from http://www.mattkruse.com/javascript/validations/
    for example, you can just do:

    setInputValue(d ocument.forms[0].selectObj,"myV alue");

    and this will work regardless of input type.

    --
    Matt Kruse
    Javascript Toolbox: http://www.mattkruse.com/javascript/


    Comment

    • datactrl

      #3
      Re: Question about SELECT element

      Thanks, Matt. It's a big help.

      Jack


      Comment

      Working...