SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Sep 2001
    Location
    Knysna, South Africa
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Drop down menus with a twist

    Hi Guys,

    I sort of ran into a brick wall with a site I'm developing. What I want to do is have 5 drop down lists. When the page is displayed, the first drop
    down list must pull info from a MySQL db using PHP. When the user selects an option from the drop down list, the second must become active (without
    reloading the page) and pull info from the db specific to the selection in the first drop down box... and so on with the 3rd 4th and 5th.

    Any help will be much appreciated...

    Cheers

    Rudi

  2. #2
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    since your hits on the database need to be done server side, i don't see how you can dynamically update your dropdowns without refreshing the page.

    Depending on how much info you have in your database, you could pull it all down at once when the page first loads and then dynamically populate your dropdowns based on a users selections.

  3. #3
    SitePoint Enthusiast kcabobert's Avatar
    Join Date
    Aug 2001
    Location
    Topeka, KS
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wanted to do something similar to what your saying and using php to populate arrays for the drop downs was the only way I ever found
    Microsoft's Motto: Resistance is futile, you will be assimilated.

    My dog's name is Jade; she is a Miniature pinscher.
    Click here to see some of her pictures

  4. #4
    SitePoint Member
    Join Date
    Sep 2001
    Location
    Knysna, South Africa
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrays & Dynamic Content via PHP & MySQL

    Hey, this sounds pretty good. To get the info into the arrays won't be a problem... but how do I get the the second dropdown list to change dynamically everytime the selection in the first drop down box changes? Will this have to be Javascript? I dunno...

    Thanks guys!

    Originally posted by kcabobert
    I wanted to do something similar to what your saying and using php to populate arrays for the drop downs was the only way I ever found

  5. #5
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you don't want the page to refresh then you will have to populate the dropdowns client side. as kcabobert was saying, you can use php to dynamically write your javascript, so that your arrays get written dynamically based on what is in your database.

    You could then use the style property to disable your dropdowns and wait until your 'populate' function releases them. Your populate function would consist of rules for populating each dropdown based on a selection, followed by the style property to enable the dropdown.

  6. #6
    SitePoint Wizard big_al's Avatar
    Join Date
    May 2000
    Location
    Victoria, Australia
    Posts
    1,661
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I'm no JS guru but here is a script I use. This only works with 2 drop downs so far but should be quite easily updated.

    Code:
    <script>
    	function Load() {
    	
    	
    	sCatSelect = new Array();
    	sCatSelect[1] = new Array; //Advertising
    	sCatSelect[1][0]  = 'Select a Sub Category'
    	sCatSelect[1][1]  = 'Embroidery Services'
    	sCatSelect[1][2]  = 'Graphic Designers'
    	sCatSelect[1][3]  = 'Newspapers'
    	sCatSelect[1][4]  = 'Office Stationary'
    	sCatSelect[1][5]  = 'Multimedia'
    	sCatSelect[1][6]  = 'Printers'
    	sCatSelect[1][7]  = 'Promotional Products'
    	sCatSelect[1][8]  = 'Sign Writters'
    	
    	sCatSelect[2] = new Array; // Agriculture
    	sCatSelect[2][0] = 'Select a Sub Category'
    	sCatSelect[2][1] = 'Environmental'; 	
    	sCatSelect[2][2] = 'Fertiliser';
    	sCatSelect[2][3] = 'Helicopter Services';
    	sCatSelect[2][4] = 'Machinery';
    	sCatSelect[2][5] = 'Produce';
    	sCatSelect[2][6] = 'Stock Station Agents';
    	sCatSelect[2][7] = 'Supplies';
    
    	//Etc etc etc etc etc ;)
    	
    	sCatSelect[0] = new Array; // Default
    	sCatSelect[0][0] = 'Make a selection from the first column'
    	
    	var total;
    	var firstChoice = document.User_Entry.First.selectedIndex;
    	for (i=0; i<sCatSelect.length; i++) {
    	document.User_Entry.CatSelect.options.length = sCatSelect[firstChoice].length;
    	total =sCatSelect[firstChoice].length;
    	}
    
    	for (n=0; n<total; n++) {	
    	document.User_Entry.CatSelect.options[n].text = sCatSelect[firstChoice][n];
    	document.User_Entry.CatSelect.options[n].value = sCatSelect[firstChoice][n];
    	}
    	}
    	
    </script>
    Hope this helps a little
    .NET Code Monkey


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
  •