Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Menu values

Status
Not open for further replies.

SBuzzT

Programmer
Aug 24, 2005
86
CA
I have a javascript which allows me to select items from one (select) menu and add them to another (which is later added to my database). The problem is I have to select the items one at a time. How can I modify this function (below) to allow me to add multiple selections at a time? The drop down allows me to do so, but only the first selection gets added. (The CountMovies() function has nothing to do with it.)

Code:
 <script language='javascript'>
  function AddMovie()
  {
    add_movie:
    with (document.pickmovies)
    {
     if (movies.selectedIndex != -1)
     {
      for (i=0; i<playlist.length; i++)
       if (playlist.options[i].value == movies.options[movies.selectedIndex].value)
       {
        alert('This movie already exists in your playlist.');
        break add_movie;
       }
      playlist.length++;
      playlist.options[playlist.length-1].text  = movies.options[movies.selectedIndex].text;
      playlist.options[playlist.length-1].value = movies.options[movies.selectedIndex].value;
     }
     CountMovies();
    }
  }
 
Code:
movies.options[i].selected
tells whether or not option is selected.
 
So I would add this in both spots?
Code:
playlist.options[playlist.length-1].text  = movies.options[i].text;
playlist.options[playlist.length-1].value = movies.options[i]
Or just like this?
Code:
playlist.options[playlist.length-1].text  = movies.options[i].text;
 
I tried this:
Code:
playlist.options[playlist.length-1].text  = movies.options[i].selected.text;
playlist.options[playlist.length-1].value = movies.options[i].selected.value;
All I get is "undefined
 
Code:
movies.options[i].selected

is either true or false; it is a value, it has no properties such as text or value. You must loop through the options to determine which ones are selected. When you find one that is selected, you use its value and text.

Code:
if( movies.options[i].selected ) {
playlist.options[playlist.length-1].value = movies.options[i].value; }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top