Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    190
    Thanks
    1
    Thanked 2 Times in 2 Posts

    multiple select box values

    i have a very simple multiple select box and a function to create an array of the selected items. that function doesnt work correctly though.

    Code:
    function confRes(){
    	var res = document.getElementById('restricted');
    	var len = res.length
    	var sel = new Array();
    	
    	for(var i = 0; i < len; i++){
    		if(res[i].selected){
    			sel[i] = res[i].value;
    		}
    	}
    }
    if i select the third item in the list, when i alert the array it will be ,,3 and if its the third and seventh - ,,3,,,7 etc.

    what am i doing wrong?
    thanks

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    190
    Thanks
    1
    Thanked 2 Times in 2 Posts
    i figured it out. i was using var i as the index. so if it would assign the index and create all of the missing ones.


  •  

    Posting Permissions

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