www.webdeveloper.com
Results 1 to 2 of 2

Thread: Creating a varied number of dropdown lists dynamically

  1. #1
    Join Date
    Apr 2014
    Posts
    26

    Creating a varied number of dropdown lists dynamically

    I'm working on an AJAX based site (which also involves PHP and MySQL) and I'm trying to create a product selection system, where someone can start with a dropdown list of very generic items, and slowly (through additional drop down menus) "narrow" down to the specific item or class of items they are looking for.



    My problem is this: I'm not sure how to go about the dynamic portion of it. Should I just create a bunch of drop down lists, and then through Javascript, hide or show them as needed, or should I create them dynamically as I need them? My other issue is that for some items, the lists may be only 2 or 3 levels deep, whereas for others, it may be 4-6 levels deep.



    I'm trying to minimize the amount of HTML code, so I can decrease the page size and browser processing time, so any advice would be helpful.

    I am quite experienced in Javascript, HTML, PHP and MySQL. Lastly, I DON'T want to use any third-party libraries, such as jQuery--it needs to be hand-coded by me.

  2. #2
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    899
    My suggestion would be to use a lovely JSON-ish object. The way I see this working is you load all of the products (and their information) into a nice JSON object. Next, javascript can dynamically build any dropdowns you need based on any criteria you set. So regardless of the number of levels in any particular dropdown flow, javascript will build them on-the-fly and have a master list of products to filter from.

    Now, without some examples to see what 'very generic items' might be, and any subsequent list, it's a little tricky for me to throw some code at you. But you certainly can do this without jQuery (or any other framework/library). And as far as page-size goes, I guess the size of the script itself might slightly increase a page load time, but I can't see it being in any way noticeable (unless you hop on a dial-up connection). Overall though it'll be pretty minimal as the idea is to have javascript generate HTML (dropdowns) on-the-fly and populate with whatever items fit a criteria.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles