Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Feb 2006
    Posts
    11
    Rep Power
    0

    Dynamic drop down box value loading


    I spend a lot of time coding a VB Script but can't get the behavior I need.

    I have 2 drop down boxes
    Car Make:*
    Car Model:*

    Depending on the Car Make drop down box value like Acura, Toyota, Honda, etc. The Car Model drop down box need to get preloaded like Accord, Civic, etc. for Honda

    Any pointers to a VBscript that does that will be appreaicted

    Thanks
    Amol
  2. #2
  3. Senior Water Wizard
    ASP Mastermind (5000+ posts)

    Join Date
    Aug 2004
    Location
    Cape Town, RSA
    Posts
    10,233
    Rep Power
    863
    Hi,

    this section of the forum is for examples only, not questions

    neways, can you post the code you have so far?

    onChange of the first drop down, reload the page, and select
    the values accordingly for the second drop down.
    Look! Its a ShemZilla


  4. #3
  5. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2926
    --moved to the HTML forum.

    what you need is known as "dependant dropdowns" and can be achieved using
    client side javascript by preloading all the data in such fashion:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    var arrMainData=new Array();
    arrMainData["main_value1"] = new Array();
    arrMainData["main_value1"]["values"] = new Array("sub_value1_1", "sub_value1_2", "sub_value1_3");
    arrMainData["main_value1"]["texts"] = new Array("sub 1 for main 1", "sub 2 for main 1", "sub 3 for main 1");
    arrMainData["main_value2"] = new Array();
    arrMainData["main_value2"]["values"] = new Array("sub_value2_1", "sub_value2_2");
    arrMainData["main_value2"]["texts"] = new Array("sub 1 for main 2", "sub 2 for main 2");
    arrMainData["main_value3"] = new Array();
    arrMainData["main_value3"]["values"] = new Array("sub_value3_1", "sub_value3_2", "sub_value3_3");
    arrMainData["main_value3"]["texts"] = new Array("sub 1 for main 3", "sub 2 for main 3", "sub 3 for main 3");
    
    function ComboChange() {
    	var objMainCombo = document.getElementById("main_dropdown");
    	var objSubCombo = document.getElementById("sub_dropdown");
    	var selIndex = objMainCombo.selectedIndex;
    	if (selIndex >= 0) {
    		var selValue = objMainCombo.options[selIndex].value;
    		if (arrMainData[selValue]) {
    			while (objSubCombo.options.length > 0)
    				objSubCombo.removeChild( objSubCombo.options[0] );
    			var arrValues = arrMainData[selValue]["values"];
    			var arrTexts = arrMainData[selValue]["texts"];
    			for (var i=0; i<arrValues.length; i++) {
    				var option=new Option();
    				option.value = arrValues[i];
    				option.text = arrTexts[i];
    				objSubCombo.options.add(option);
    			}
    		}
    	}
    }
    </script>
    </head>
    <body onload="ComboChange();">
    <form>
    <select id="main_dropdown" onchange="ComboChange(this);">
    <option value="main_value1">First</option>
    <option value="main_value2">Second</option>
    <option value="main_value3">Third</option>
    </select>
    <select id="sub_dropdown"></select>
    </form>
    </body>
    </html>
    just make sure to have the above syntax, change the ID to the proper id
    and it should work fine.
    Last edited by Shadow Wizard; February 21st, 2006 at 04:15 AM.
  6. #4
  7. No Profile Picture
    Contributing User
    ASP Mastermind (5000+ posts)

    Join Date
    Aug 2005
    Location
    North East, UK
    Posts
    6,191
    Rep Power
    141
    If you want to use it from a database then you have a few options.
    You can use the default ASP VBScript where you would submit the form and then the submitted value would be the query for the second dropdown.
    e.g. http://computer-helpforum.com/asp/select.asp

    You could combine with the javascript example where you output your database fields into javascript arrays.

    Or you could use Ajax to call the content for the dropdown.
    http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm
  8. #5
  9. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Feb 2006
    Posts
    11
    Rep Power
    0
    Thanks for the reply

    Degsy, can you please share with me the code for http://computer-helpforum.com/asp/select.asp?

    On the similar point, is client side or server side script better in performace, bandwidth utilisation?

    Thanks
  10. #6
  11. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Feb 2006
    Posts
    11
    Rep Power
    0
    Shadow wizard your script is great too. since i don't need to query database to have those drop down menus filled I can use this script but the script could get ugly considering how many car companies we have and how many models.

    So tell me guys is a client side script better or server side script of the data is not populated from the database and how do they fair for performance and bandwidth utilisation?

    Any other pros and cons?
  12. #7
  13. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2926
    if it's not from database then you really better use client side approach.
    it's faster as it don't require page submit each time the user change selection
    and thus it also consume less bandwidth: the page is loaded only once.
    as for the code getting long you can put all the code between the <script>
    and </script> inside seperate file called "cars.js" for example then include the
    file using this code:
    Code:
    <script type="text/javascript" src="cars.js"></script>
  14. #8
  15. No Profile Picture
    Contributing User
    ASP Mastermind (5000+ posts)

    Join Date
    Aug 2005
    Location
    North East, UK
    Posts
    6,191
    Rep Power
    141
    Originally Posted by Not_a_techie
    Shadow wizard your script is great too. since i don't need to query database to have those drop down menus filled I can use this script but the script could get ugly considering how many car companies we have and how many models.

    So tell me guys is a client side script better or server side script of the data is not populated from the database and how do they fair for performance and bandwidth utilisation?

    Any other pros and cons?
    As stated, if you don't have any Server-Side code then just use javascript.

    You don't have much choice about the complexity of the code. There are different methods but in the end aslong as the code is good and you have a good server then the script should load fast.

    Checkout http://www.autotrader.co.uk/ for an example
  16. #9
  17. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Feb 2006
    Posts
    11
    Rep Power
    0
    Thanks guys so client side javascript is the answer. I have started to work on it.

    I was told Visual Studio 2005 for web development but I am finding it tough to use. Can someone recommend an WYSIWYG editor where its easy to develop as well as I can get some pre loaded script in the application like form mail, comments\feedback script, email password script, etc.

    Preferably a free editor
  18. #10
  19. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2926
    Visual Studio is great for .NET development. for html or javascript
    I recommend Notepad, I'm using this text editor for years and years
    and it's great.
  20. #11
  21. No Profile Picture
    Contributing User
    ASP Mastermind (5000+ posts)

    Join Date
    Aug 2005
    Location
    North East, UK
    Posts
    6,191
    Rep Power
    141
    I would not recommend Notepad as a script editor. I would recommend an editor with atleast syntax highlighting.

    Notepad2, Cpad and many others have Syntax highlighting. You would probably have to test to find one you like.

    http://zantii.net/index.php?option=content&task=category&id=69

    1st page has alot of inbuilt scripts
    http://www.evrsoft.com/1stpage3.shtml


    And NVU is pretty good
    http://www.nvu.com/


    or if you have the money then get Dreamweaver
  22. #12
  23. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Feb 2006
    Posts
    11
    Rep Power
    0
    Thanks for the input guys. I will try it out and let you know how it goes
  24. #13
  25. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Mar 2006
    Posts
    11
    Rep Power
    0
    Hi Guys,

    I'v just found this thread in Google and have read everything and registered,

    I am also trying to find out how to create some Dynamic "dependant dropdowns" BUT i want mine to be server side, so they self generate depending on what is in the db at any given time...

    The http://computer-helpforum.com/asp/select.asp page looks to be what i want, Is this Dynamic ?????

    My plan is to have 4 selections to search a db and for that search to generate a master detail page.

    The 4 selections are

    Var - 1 - Product Type (Predetermined selection of about 5 NOT Dynamic)
    Var - 2 - Price Range (Drop Down - NOT Dynamic)
    Var - 3 - Make - (Dynamic Drop Down List Dependant on Var 1 & 2)
    Var - 4 - model - (Dynamic Drop Down List Dependant on Var 1, 2 & 3)

    Please would one of you guys be able to Point me in the right direction or give me an example of the actual Server side code to do this ?????

    ---------------------------------------------------------

    WYSIWYG editors

    I dont know exactly what you want or what it is for BUT if it is to put on a page of your website to insert data through a form i found a very good one that turns a <textarea> in to a WYSIWYG editor of the type you find in forums (what i'm typing in to now!)

    It's Called RTE Rich Text Editor and can be found Here -

    http://www.webwizguide.info/asp/sample_scripts/RTE_application.asp



    Thank you and I hope that was what you were Looking for...
  26. #14
  27. No Profile Picture
    Contributing User
    ASP Mastermind (5000+ posts)

    Join Date
    Aug 2005
    Location
    North East, UK
    Posts
    6,191
    Rep Power
    141
    Here is an example of Pure ASP dependent dropdown
    http://computer-helpforum.com/asp/as...dropdown_2.asp

    See attachment for code


    You can always add a bit of javascript for user friendlyness (submit on change etc)
    Attached Files
  28. #15
  29. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Mar 2006
    Posts
    11
    Rep Power
    0
    Cheers for the reply Degsy,

    I dont suppose you know of any free dreamweaver plugins or extensions that will help me create some of these dependand drop downs.

    I found one for e7.50 but would rather not spend the money!!!
Page 1 of 2 12 Last
  • Jump to page:

Similar Threads

  1. Two linked Dynamic Drop Downs
    By vijaysingh in forum ASP Development
    Replies: 5
    Last Post: February 20th, 2006, 06:00 AM
  2. Dynamic DB driven drop down boxes
    By davemcdougall in forum ASP Development
    Replies: 4
    Last Post: June 30th, 2005, 07:39 AM
  3. dynamic drop down list
    By tiger99 in forum ASP Development
    Replies: 3
    Last Post: October 31st, 2004, 07:44 PM
  4. dynamic drop down list box loading problem!
    By c1ph3r in forum ASP Development
    Replies: 2
    Last Post: October 18th, 2004, 03:15 PM
  5. Creating Dynamic Drop down boxes: ASP.NET
    By tommylim in forum .NET Development
    Replies: 0
    Last Post: January 16th, 2003, 07:53 AM

IMN logo majestic logo threadwatch logo seochat tools logo