Results 1 to 3 of 3

Thread: add items to a combobox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    84
    How do I add items to a combobox in a HTML doc with JavaScript?

    the Combobox looks like this:

    <SELECT id="select2" name="name2" style="HEIGHT: 22px; WIDTH: 142px">
    <OPTION selected value="n/a"></OPTION>
    </SELECT></P>


    and here's the JavaScript function that I've got so far.
    Depending on what item in another combobox the user clicked on, different items go into combobox2

    Code:
    function select1_onclick(val) 
    {
    	select2.clearAttributes;
    	switch (val)
    	{
    		case "n/a": select2.clearAttributes; break;
    		case "hs": 
                               
                               //add items to select2 
    
                               break;
    		case "hm":
    
                               //add items to select2 
    
                               break;
    		default:
                               break;
    	}
    }
    Any suggestions?
    Thanks in advance, Nina

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    this code adds items to a <select> box using Javascript

    Is this any use to you?



    Code:
    <BODY><HEAD>
    <script Language="JavaScript">
    var i;
    function AddItem(){	
    	i++;		
    	var oOption = document.createElement("OPTION");	
    	oOption.text="Apples";	
    	oOption.value=i;	
    	document.frm1.select1.add(oOption);	
    }
    </script>
    </head>
    <form name="frm1">
    <SELECT id=select1 name=select1 size=2 style="HEIGHT: 134px; WIDTH: 258px">
    
           
    </SELECT>            
    </form>       
    <input type="button" onclick="AddItem()" value="Click">
    </BODY>
    </HTML>
    Mark
    -------------------

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    84

    Thumbs up

    Thanks, Mark
    That's just about what I need.

Posting Permissions

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



Click Here to Expand Forum to Full Width