SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    populating multiple select drop down's

    Hi,
    Im using the below bit of code to populate a single select box and it works fine. However I want to add more select boxes and populate them with the same information, even after I give them the same name in the id tag it will only ever set the values on the first select.

    What am I doing wrong.
    code:
    Code JavaScript:
    function getVehicleList(sel)
    {
    	var vehicleCode = sel.options[sel.selectedIndex].value;
    	document.getElementById('vehicle').options.length = 0;	// Empty city select box
    	if(vehicleCode.length>0){
    		var url = '../../includes/getData.php?vehicleCode='+vehicleCode;	
    		ajax.requestFile = url;// Specifying which file to get
    		ajax.onCompletion = createVehicles;	// Specify function that will be executed after file has been found
    		ajax.runAJAX();		// Execute AJAX function
    	}
    }
     
    function createVehicles()
    {
    	var formObj = document.forms['resortInput'];
    	var obj2 = document.getElementById('vehicle');
    	eval(ajax.response);	
    }

    thanks chris

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you want a group of controls with the same identifier you can't use an 'id'- use the name attribute, and handle them with the node list you get from document.getElementsByName('thename').

  3. #3
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mrhoo View Post
    if you want a group of controls with the same identifier you can't use an 'id'- use the name attribute, and handle them with the node list you get from document.getElementsByName('thename').
    Thanks for the help, but im still lost, and I know its because I havent a clue with this javascript!!!!

    I have change the code to include document.getElementsByName('vehicle[]').options.length = 0; instead of getElementsById, but now I get an error message

    document.getElementsByName("vehicle[]").options has no properties

    what am I missing?


    Code JavaScript:
    function getVehicleList(sel)
    {
    	var vehicleCode = sel.options[sel.selectedIndex].value;
    	document.getElementsByName('vehicle[]').options.length = 0;	// Empty city select box
    	if(vehicleCode.length>0){
    		var url = '../../includes/getData.php?vehicleCode='+vehicleCode;	
    		ajax.requestFile = url;// Specifying which file to get
    		ajax.onCompletion = createVehicles;	// Specify function that will be executed after file has been found
    		ajax.runAJAX();		// Execute AJAX function
    	}
    }
     
     
    function createVehicles()
    {
    	var formObj = document.forms['resortInput'];
    	var obj2 = document.getElementsByName('vehicle[]');
    	eval(ajax.response);	
    }

    Thanks
    Chris


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
  •