Results 1 to 6 of 6

Thread: Javascript: Select Options [Resolved]

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2004
    Posts
    70

    Javascript: Select Options [Resolved]

    Hi,

    I've 2 select boxes. When the user changes the option in the first select box, the options in the second select box will change/populated.
    I used the onchange event on the first select box, but the options in the second select box is not populated.

    My codes:
    Code:
    <html>
    
    <head>
    <script language="Javascript">
    
    var NW = new Array("Network/User Admin", "Hardware", "Software");
    var BA = new Array("Email", "Intranet");
    
    function main_change(mymain) {
    	var _main = mymain.value;
    	
    	if (_main == "NW") {
    		
    		for (var k=0; k< NW.length; k++) {
    
    			OPT = new Option;
    			OPT.Text= NW[k];
    			OPT.Value= NW[k];
    			
    			document.forms['issue']['subCat'].options[k] = OPT;
    			
    		}
    
    				
    	}
    	else if (_main == "BA") {
    
    		for (var k=0; k< BA.length; k++) {
    
    			OPT = new Option;
    			OPT.Text= NW[k];
    			OPT.Value= NW[k];
    			
    			document.forms['issue']['subCat'].options[k] = OPT;
    			
    		}
    
    	}
    
    	
    }
    </script>
    
    </head>
    <body>
    <form name="issue">
    <table>
    <tr>
    		<td>Main Category:</td>
    		<td width=10>	<select name="main" onchange="main_change(this);">
    				<option>Please Choose One...</option>
    				<option value="NW">Network</option>
    <option value="BA">Business App</option>				
    			</select>
    		</td>
    		<td>Sub Category:</td>
    		<td>	<select name="subCat">
    				<option>Please Choose One...</option>
    		
    			</select>
    		</td>
    	</tr>
    
    </table>
    </form>
    
    </body>
    </html>
    Last edited by velvetskies; Aug 17th, 2004 at 07:21 PM.

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