SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2002
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    build a dynamic dropdown?

    hey, i want to have a drop down menu that builds a second drop down menu's <option>'s.

    basically, i'd want to choose an option from one drop down, hit submit, and that option will be added to the other select..

    anyone know a tutorial that could show me where to do this?

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2002
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I coded up a little demo for you. I didn't use a submit button (although you could), instead I used the onChange event handler.

    http://travis.squidfingers.com/select.html
    travis

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2002
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hm. that's cool, but not quite what i was looking for.

    basically, if i have dropdown #1 having options of "option 1", "option 2", "option 3" i want to hit submit and have it fill that second dropdown with the same option that i just selected. so if i chose "option 3", "option 3" will have been added to the 2nd dropdown.

    does that make sense?

  4. #4
    SitePoint Member
    Join Date
    Nov 2002
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In that case i think this should do it (ammended podlob's function slightly).



    Code:
    function changeMenu(sel)
    {
    	var f = sel.form;
    	var s = f.menu2;
    	var v = sel.options[sel.selectedIndex].value;
    	if(v == "") return;
    	var amountOpts = s.options.length;		
    
            s.options[amountOpts] = new Option(v,v);
    	s.focus();
    }
    vibes

  5. #5
    SitePoint Zealot
    Join Date
    Feb 2002
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    excellent.

    i'll modify it so that the value and the text inside the OPTION are different, but that does the trick! thank you!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •