Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 3 123 LastLast
Results 1 to 15 of 37
  1. #1
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    populating drop down menu from the database

    hiya

    I want to populate 2 menu from the database but once a value is chosen from the first menu the values in the second menu will be arranged according to the chosen value in the first menu.

    Something like different events held at different branches at different dates. So if the user chooses one branch then the date menu has to be arranged with the dates that are valid for that branch. I have branches and dates coloumns in my table in the database but I couldn't figure out how to start doing it.

    Does anyone have any ideas?

    Thanks

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Seems like two questions to me:
    - populating dropdows
    - linkink dropdows clientsided

    this is a tread that covers both (at first look). Similar questions are posted here frequently so a search will turn up some usefull threads.

    http://www.codingforums.com/showthre...ight=drop+down

    Personally, i would split it up and create a framepage with the first dropdown in the top frame. put an onclick='submit();' on it and then load the second dropdown in another frame. The value that was selected in the first dropdown will be used in the sql-satement to select the recordset for the second dropdown.

    I've you would like to give this a try, let us know.

  • #3
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    If you were doin this in .NET it'd be easy

    Anyway - depending on how much data I was looking at - how many branches, etc. - I'd go about this one of two ways. Load everything, or load the first thing and make the page repopulate itself.

    You could load everything (ie: the lists of dates at different branches) into javascript arrays, and keep your <select> boxes in <div>'s that you can rewrite as necessary. If you need more detail on populating javascript variables from server-side data, or on rewriting HTML content dynamically, just shout.

    Alternatively, you could just load the list of branches, and the first list of dates, and make the <select> onChange submit a branch id in the querystring which grabs the dates for that branch and rewrites the page with the correct dates.

    Any help?

  • #4
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh I am completely lost guys Thanks for suggestions but I can't get my head of those. Populating one dropdown from a database is not a problem, what confuses me is how to make it work in a way that whatever value is in the first drop down will affect the dates on the other one.

    And once the user submit this query it will then select* from the table where Branch_Name=<% %> and date=<% %>

    Populating the menus is one vb scripy and using it on sql query is another script where confuses me.

    About javascript arrays I couldn't really understand what you mean. My head goes blank..sorry can you tell me bit more?

    Thanks

  • #5
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    pinkcat_02,

    well. quick recap. 2 options : load in everything into the browser and use javascript topopulate the second dropdownbox.
    or
    load a page withthe first dropdown (name='branche').
    (no problem). Submit this form to an asp page. In this page, you'll build the sql statement to select the possible dates. Something like
    Code:
    sql="select id,dates from table where branche_Name='aname'"
    sql=replace(sql,"aname",request.form("branche")
    so the branche-name that was selected it put into the condition of the sql-string.

    now, the resulting recordset goes into the second dropdown + you include a hidden field in the form with the brachename in it.

    when you post that second form, you select the record(s) with the right branchename and date.


    Does this make any sense to you?

  • #6
    Regular Coder
    Join Date
    Nov 2002
    Location
    Loughborough (UK)
    Posts
    209
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASP DD menus

    OK, I'm not web expert, but I can do these db populated DD menus. This is how I do it, and I think it is fairly straight-forward to follow. I think you'll be able to work it around your db.

    <select name="group">

    <%
    strSQLfran = "SELECT id, franchise from groups"
    Set objRSfran = oConnection.Execute(strSQLfran)
    Do While Not objRSfran.EOF
    %>

    <option value="<% = objRSfran("id") %>"><% = objRSfran("franchise") %></option>

    <%
    objRSfran.MoveNext
    Loop
    objRSfran.Close
    Set objRSfran = Nothing
    %>

    </select>

  • #7
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Populating one dropdown from a database is not a problem, what confuses me is how to make it work in a way that whatever value is in the first drop down will affect the dates on the other one.

  • #8
    New Coder
    Join Date
    Nov 2002
    Location
    Oxford
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yup client side is the way, I reckon.

    -use asp to populate the first select menu (OK)
    -use asp to populate a set of javascript arrays (eg.)
    -use the onChange event on the first select menu to trigger a client-side function which populates the second select menu accordingly with the data from one of the arrays.
    -don't forget to set the length of the select menu first!

    That's how I always do it, anyway.


    [m03;5]

  • #9
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I couldn't do it, does anyone has an example of this javascript arrays with the required ASP which can be an example that I can have a look at?

    Thanks

  • #10
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    raf

    I have done it the way u have told with populating the first drop down menu and then poulating the second with the information it got from the first one...Cheers...

    Now I wonder if there is any way of submitting the first menu and keeping it on the same page with the second one, something like it will submit itself without an action so that two menus will stay in the same page?

    Thanks

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    Originally posted by pinkcat_02
    Now I wonder if there is any way of submitting the first menu and keeping it on the same page with the second one, something like it will submit itself without an action so that two menus will stay in the same page?
    remote scripting, it is much easier in .net as earlier mentioned, but can also work in classic asp. Here is a tutorial:
    http://www.devguru.com/features/tuto...cripting1.html
    I am the luckiest man in the world

  • #12
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    pinkcat_02,

    look at my first post.
    just use a frampage. In the top frame (or left frame) you display the page with the first dropdown. In the form tag of this page, you include a target that points to the second frame (below or right). If you submit the first page, the second dropdown will appear in the other page. You can then set the target in this second page to "parent" or even to a third frame
    If you wan't you can submit the form using a bit of (on-click) javascript (but i woudn't do that. not everyone is that heppy about javascript)

    When you initially load the frameset. The second (third ... frame's can be an empty page, or a page saying 'The results will be shown her, thanks to Codingforums.com'


    Now. You can of coarse doall this clientsided (using javascript or a DSO with XML) but this means youre only coding for js-complient browsers (or with the DSO even for IE5+) + that you need to load in a lott of data (depending on how many options you've got in the dropdowns).

  • #13
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i have tried using iframes as my template is table based. i tried to put two of the asp in the cell of the table but I ended up getting ! populated menu and one empty one:

    Once I select a value from the first menu it then repopulates the same menu with the second menus options leaving the second menu still empty where I can say there is no function of the second menu.

    I think I am doing something wrong but I couldn't figure it out as it is the first time that I am using iframes. I have used it like the code below:

    <td height="21"><IFRAME
    src="dropdown.asp" target="_top" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" bordercolor="#000000"></iframe>

    &nbsp;
    <IFRAME
    src="events.asp" target="_top" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" bordercolor="#000000"></iframe>

    </td>

    dropdown.asp is the one that populates the first menu
    events.asp is the one that gets the values from the first menu and populates it according to it.

    Thanks

  • #14
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    as another option I put two of the menus in the same ASP which is called dropdown.asp and called it in iframe in my page .

    With this codebelow it populates the first table but it doesn't show the second one it gives HTTP/1.1 404 Object Not Found error.

    <form>
    <select name="Branch" onChange="if (this.value.length > 0) {window.location.href=this.value;}">


    <%

    Dim DataConn
    Dim CmdPopulateEvents
    Dim SQL
    Dim CURRENT_STATE_NAME
    %>

    <%
    CURRENT_Branch_Code = ""
    %>



    <%
    Set DataConn = Server.CreateObject("ADODB.Connection")
    Set CmdPopulateEvents = Server.CreateObject("ADODB.Recordset")
    %>


    <%

    DataConn.Open "DBQ=" & Server.Mappath("\ty\x.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"

    SQL = "SELECT DISTINCT Branch_Code FROM Event"
    CmdPopulateEvents.Open SQL, DataConn
    %>



    <%While Not CmdPopulateEvents.EOF%>

    <option <% If CURRENT_Branch_Code = CmdPopulateEvents("Branch_Code") Then %>
    <% Response.Write(" selected ") %><% End If %>value="<%= CmdPopulateEvents("Branch_Code") %>"><%= CmdPopulateEvents("Branch_Code") %></option>

    <%
    CmdPopulateEvents.MoveNext
    Wend
    %>

    <%

    CmdPopulateStates.Close
    Set CmdPopulateEvents = Nothing
    DataConn.Close
    Set DataConn = Nothing
    %>


    </Select>

    <%
    Set DataConn = Server.CreateObject("ADODB.Connection")
    Set CmdPopulateEvents = Server.CreateObject("ADODB.Recordset")
    %>


    <%
    DataConn.Open "DBQ=" & Server.Mappath("\ty\x.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"

    sql="select Event_Name from Event where Branch_Code='aname'"
    sql=replace(sql,"aname",request.form("Branch"))

    CmdPopulateEvents.Open SQL, DataConn
    %>

    <Select Name="Event_Name" size="1">
    <%While Not CmdPopulateEvents.EOF%>

    <option value="<%= CmdPopulateEvents("Event_Name") %>"><%= CmdPopulateEvents("Event_Name") %></option>

    <%
    CmdPopulateEvents.MoveNext
    Wend
    %>

    <%

    CmdPopulateEvents.Close
    Set CmdPopulateEvents = Nothing
    DataConn.Close
    Set DataConn = Nothing
    %>
    </Select>

    </form>

  • #15
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    IMHO I just think that multiple select combos (not a multiple select, but combinations of selects, i.e. "combo boxes") are too much work client-side... probably not too bad if I had time to really mess with it, but I don't!

    I would just post the page to itself when you selected something onchange, and then add the other combo box... yeah, it refreshes the page. But it also saves you hour(s) of headaches. So what?

    spudhead is right about .NET, it does this easily... but using remote scripting to accomplish this in classic ASP is just another headache when all you have to do is just post to the page again, and it's simple that way...
    Last edited by whammy; 02-27-2003 at 12:34 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

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