Results 1 to 6 of 6
  1. #1
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: conditional drop-downs on a web page

    You are correct in that there are two basic ways: Static and Dynamic.

    Even if you go the static route, you can still drive the data from a data source. Just remember, you can always include Javascript blocks within the <% %> blocks in an ASP page. The difficulty, as you mentioned, is writing the arrays and logic within Javascript. I'm sure there are abundant examples on help-websites.

    The other route is to dynamically post back each time a choice is made. This is where ASP.NET will help. It has a drop-down property to force a postback when the selection is changed. I write pages like this all the time and performance is usually adequate (depending on the database performance, of course).

    I don't mind using client-side scripting (static) when it's necessary or appropriate. If you're working with a large number of items, I would almost definitely use server-side scripting (dynamic) for this one...

  2. #2
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: conditional drop-downs on a web page

    There is a way to use normal ASP, and fill a page that is already loaded, without reloading that page. Use a 'hidden' inline frame. (Setting it's height and width to 0). Then use client side scripting to 'reload' the javascript page when one of your combo boxes is changed. What needs to load in the inline frame is more scripting that 'modifies' the combo boxes you want modified.

    I personally can't stand javascript, and I'm lucky enough to write a lot of web stuff for our Intranet (a controlled IE only environment), so I mainly use VBScript. I have built this process once. It didn't repopulate combo boxes, instead, it filled out portions of a form, from the selection of a combo box.

    So let's recap. Build an ASP page that receives the name of the combo box, and the current selection. Have that asp page product HTML/scripting that modifies the appropriate combobox (on the parent window) to contain the new data. On the OnClick event of each combo box, 'navigate' the 'invisible' inline frame to that asp page with the appropriate querystring variables (combo name and value).

    And there you have it. Dynamic data interchange without reloading an .asp page. Enjoy! <img src=/S/sailing.gif border=0 alt=sailing width=25 height=25>

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: conditional drop-downs on a web page

    Drew, I've never used the <IFRAME> tag before. I notice it seems to default to a certain height and provide a scroll bar. If the iFrame is an unknown size, is there any way to make it more dynamic?

    My old HTML reference notes that the tag is "transitional," and suggests <DIV> and CSS to accomplish the same thing. That doesn't make any sense to me, unless I also use an OBJECT element inside...

    <OBJECT DATA="cholesterol.html" TYPE="text/html" STANDBY="Retrieving document.
    Please wait." WIDTH="400" HEIGHT="400">
    You must not like OBJECT tags. ;-)
    </OBJECT>

    Doesn't seem any more standards-compliant or widely supported...or any better at sizing itself.

  4. #4
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: conditional drop-downs on a web page

    I don't use an inline frame very often, unless I am pulling off a 'hidden' server comm trick. In those cases, I just set the height=0 and width=0. I know that if you don't set an ID property, that Netscape has a problem with them.

  5. #5
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: conditional drop-downs on a web page

    Well, since I posted my question I found some javascript that is actually not too hard to grok (for some reason, javascript people tend to code complexly). It is all static values & is mildly painful to work with (who likes typing?). I am trying to get the people here to not drill-down too far so I don't have to mess with more than Choice 1 -> Choice 2. If they go for that the static method will work fine.

    And you with your ASP.NET! I don't use that yet. I may in the future (they are promoting me to Sys Analyst III) but right now it's all classic ASP. I may need to run a post-back on the form I am working on in any case so if I do & the conditional drop-downs are more complex than *I* would like, perhaps I'll go the load from server option for the drop downs. Which means some kind of event handler for the drop-downs (no multiple submit buttons please).

    But at the moment I have something that works, so we'll see if it'll be a winner or not.

  6. #6
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    conditional drop-downs on a web page

    I have looked around on the webbernet and have found a *lot* of incomplete discussions and mysterious code samples and dead links to tutorials on doing this, so I thought maybe the Loungers might be a good resource...

    Basically, I need to implement 3 conditional drop-downs on a webpage so that Choice 1 -> Choice 2 -> Choice 3. My bias is to use Javascript if possible to avoid re-loading the page, but the javascript I have managed to scare up has statically defined arrays, which is not optimal. Does anyone know of a method for loading javascript arrays from a db when the page initially loads? And what is a simple way to implement the drop-downs in javascript?

    I can go the ASP/SQL Server route as well (that is, reload the page on each select to populate the drop-downs as they are selected) but, like I said, I like the interactivity of Javascript and would prefer to not do re-posts to the server. However, the contents of the drop-downs are a little complex (especially at the third level) so a statically-defined array is going to be hurtful to work with. And I don't like pain...

    Any advice? Basically, I want something relatively understandable, easy to implement and maintain that doesn't hard-code data. Or just general comments on doing conditional drop-downs on a webpage?

    TIA
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20>

Posting Permissions

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