Selecting items in a list/menu with javascript

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

    Selecting items in a list/menu with javascript

    How can I use javascript to select Items in a List/Menu? For example:
    (value1, value2) will select value1 and value2 in a list menu....

  • Joshie Surber

    #2
    Re: Selecting items in a list/menu with javascript

    > How can I use javascript to select Items in a List/Menu? For example:[color=blue]
    > (value1, value2) will select value1 and value2 in a list menu....[/color]

    Can you clarify and include some sample code? We may be able to help if
    we could better understand the problem.

    Comment

    • Brian Ciarcia

      #3
      Re: Selecting items in a list/menu with javascript


      OK.. I'll do my best to clarify. A user does a search and pulls up a
      list of clients. I have a form on the side of the list that they can
      use to add a new client if its not in the list. If the client is in the
      list, they can click on the client's name and it will poplulate that
      form with all of their information so they can update the record. One
      of the fields is a List/Menu box that allow for multiple selections. So,
      I am passing, for example onclick=popform ('Show, Sold') which are two
      elements in that menu box. I need to have both of those selected when I
      do the onclick event. Is that possible?

      Does that help?


      *** Sent via Developersdex http://www.developersdex.com ***

      Comment

      • Joshie Surber

        #4
        Re: Selecting items in a list/menu with javascript

        If I am understanding right, you are trying to populate a couple of
        text fields from the selection in a <select> tag selection?

        <option value="textfiel d1|textfield2" onclick="popfor m(this)">some
        option</option>

        function popform(el) {
        fields = el.value.split( '|');
        this.form.textf ield1.value = fields[0];
        this.form.textf ield2.value = fields[1];
        }

        Is this something like what you were hoping for?

        Comment

        • Joshie Surber

          #5
          Re: Selecting items in a list/menu with javascript

          Never mind, I just figured out what you want.

          el = document.formNa me.selectName;
          opts = el.options;
          for (i=0;i<opts.len gth;i++) {
          if (opts[i].selected) {
          // do something with this option
          }
          }

          Comment

          Working...