The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 7 of 7

Thread: Drop Down ASP Boxes? HELP!

  1. #1
    228
    posts
    All the small things!

    Drop Down ASP Boxes? HELP!

    Hey everyone, Im working on a form in HTML/asp, where when you select a box the page refreshes and the next box with the corrosponding info appears, this works for the first two boxes but by the third box the first box has reset, reseting everything, how do I stop this? Thanks
    Fidelity88

  2. #2
    I've done this kind of thing before so I've got a good idea what you mean but could you post some code, thanks
    now with blog, click here

  3. #3
    228
    posts
    All the small things!
    ok, here is the code for the page I am working on.

    Code:
    <!-- #include file="./adovbs.inc" -->
    
    <%Rep=Request.Cookies("Login")("Rep")%>
    <%Cookie=Request.Cookies("Login")("ID")%>
    
    <%
    
    Cookies=1
    
    Dim DatabaseConn
    Dim RecordSet
    Dim strSQL 
    Dim RecordNo
    
    RecordNo = (Request.Cookies("Login")("Rep"))
    Set DatabaseConn = Server.CreateObject("ADODB.Connection")
    DatabaseConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("clients.mdb")
    Set RecordSet = Server.CreateObject("ADODB.Recordset")
    strSQL = "SELECT replist.* FROM replist WHERE ID_no=" & RecordNo
    RecordSet.CursorType = 2
    RecordSet.LockType = 3
    RecordSet.Open strSQL, DatabaseConn
    
    %>
    
    
    <!--------Page Body----------->
    
    
    <html>
    <body>
    <font face="arial">
    <br>
    
    
    <table width=600 cellpadding=0 cellspacing=0 border=0> <tr> <td colspan=2> <strong>Place Order </td> </tr> <% RecordSet.Close Set RecordSet = Nothing %> <!------------Company Select Box-----------------> <tr> <td align=right> <br> <form name=form action=order.asp method=get> Company Name: <select> <% Set RecordSet = Server.CreateObject("ADODB.Recordset") strSQL = "SELECT clientlist.* FROM clientlist WHERE RepNo=" & Rep RecordSet.Open strSQL, DatabaseConn Do While not RecordSet.EOF Response.Write("<option>") Response.Write(RecordSet("CompanyName")) Response.Write("</option>") RecordSet.MoveNext loop RecordSet.Close Set RecordSet = Nothing %> </select> <font face=arial size=2>">Create New Account! <!-------------------------Brand Select Box------------------------> <br> Brand: <select name=brand> <% Set RecordSet = Server.CreateObject("ADODB.Recordset") strSQL = "SELECT brands.* FROM brands WHERE Company" RecordSet.Open strSQL, DatabaseConn Do While not RecordSet.EOF Response.Write("<option name=company value=" & RecordSet("Company_ID") & ">") Response.Write(RecordSet("Company")) Response.Write("</option>") RecordSet.MoveNext loop CompanyNo = Request("brand") RecordSet.Close Set RecordSet = Nothing %> </select> <br> <!-------------------Name Select Box---------------------> <% if CompanyNo = "" then %> Wait <% else %> Name: <Select name=name> <% Set RecordSet = Server.CreateObject("ADODB.Recordset") StrSQL = "SELECT inventory.* FROM inventory WHERE Company_ID=" & CompanyNo RecordSet.Open strSQL, DatabaseConn Do While not RecordSet.EOF Response.Write("<option name=name value=" & RecordSet("name_ID") & ">") Response.Write(RecordSet("Name")) Response.Write("</option>") RecordSet.MoveNext loop Name_ID = Request("Name_ID") RecordSet.Close Set RecordSet = Nothing %> </select> <br> <% end if %> <!--------------------------Stain Select Box------------------> <% if Name = "" then %> Wait <% else %> Stain: <select name=stain> <% Set RecordSet = Server.CreateObject("ADODB.Recordset") StrSQL = "SELECT inventory.* FROM inventory WHERE name_ID=" & Name_ID RecordSet.Open strSQL, DatabaseConn Do While not RecordSet.EOF Response.Write("<option name=name value=" & RecordSet("Stain") & ">") Response.Write(RecordSet("Stain")) Response.Write("</option>") RecordSet.MoveNext loop Stain = Request("Stain") RecordSet.Close Set RecordSet = Nothing %> </select> <br> <% end if %> <!------------------------------End of Drop Downs----------------------------------------->

    Does this make sense? Each of the drop downs just resets when the page refreshes and I lose all my old values!
    Thanks
    Fidelity88

  4. #4
    try this, I take it the page is resetting using JavaScript (guessing with that really)

    <select onchange="FirstDrop()">

    then in the function...

    function FirstDrop(){
    var 1st;

    var selLength = firstdrop.length;
    var selectedCount = 0;

    var i;

    for(i=selLength-1; i>=0; i--)
    {
    if(firstdrop.options[i].selected)
    {
    1st = firstdrop.options[i].value;
    deleteOption(theSelFrom, i);
    selectedCount++;
    }
    }

    self.location.href = "thispage.html?firstdrop="+ 1st
    }

    then when the page refreshes it has been passed a parameter called firstdrop. Then you can add that to your drop down

    <select>
    <% Set RecordSet = Server.CreateObject("ADODB.Recordset")
    strSQL = "SELECT clientlist.* FROM clientlist WHERE RepNo=" & Rep
    RecordSet.Open strSQL, DatabaseConn
    Do While not RecordSet.EOF
    if firstdrop = "WHATEVER" then
    Response.Write("<option selected>")
    else
    Response.Write("<option>")
    end if
    Response.Write(RecordSet("CompanyName"))
    Response.Write("</option>")
    RecordSet.MoveNext
    loop
    RecordSet.Close
    Set RecordSet = Nothing %> </select>

    I had a page with 8 drop downs on it one time and this is how I did it. Might be a better way to do this with storing the selected drop down in a session variable but this is how I did it so I know this works

    let us know how it goes
    now with blog, click here

  5. #5
    228
    posts
    All the small things!
    Hey sorry to be a pain, but Im a real newbie when it comes to ASP and stuff, could you show me how this would be implemented into my code? Im not sure how all this works yet, I mean Ive been only doing this for about a month and a half now so...
    Thanks
    Fidelity88

  6. #6
    pou-pou's Avatar
    719
    posts
    Formerly know as gnu-
    yeah, with javascript it's almost easy

    check [this] out. those first two links should get you started

  7. #7
    In the Select tag add <select onChange="FirstDrop()"> and then when the value of the select changes it calls the javascript function which reloads the page passing it a parameter called firstdrop. Then when it comes to displaying the select you just changed it will display each value from the database and then, phew, it will come to the value that matches the parameter and thats when the option tag includes <option selected> meaning that this is the selected option in the drop down



    kinda confusing my explanation, this site does it better
    http://www.webconcerns.co.uk/asp/combo/combo.asp

    similar to what I was trying to say above, hope this helps
    now with blog, click here

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
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012