Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old July 23rd, 2007, 06:59 AM
TimLensen TimLensen is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Location: Netherlands
Posts: 326 TimLensen User rank is Second Lieutenant (5000 - 10000 Reputation Level)TimLensen User rank is Second Lieutenant (5000 - 10000 Reputation Level)TimLensen User rank is Second Lieutenant (5000 - 10000 Reputation Level)TimLensen User rank is Second Lieutenant (5000 - 10000 Reputation Level)TimLensen User rank is Second Lieutenant (5000 - 10000 Reputation Level)TimLensen User rank is Second Lieutenant (5000 - 10000 Reputation Level)TimLensen User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 3 h 5 m 15 sec
Reputation Power: 88
Dynamic Dropdowns

Since I just wrote this for a member in this thread, I reckoned I might just as well post it here.

Code:
<script type="text/javascript">
    function RefreshForm()
    {
        document.getElementById("SubmitType").value = "Refresh"
        document.forms[0].submit();
    }
    function SubmitForm()
    {
        document.getElementById("SubmitType").value = "Submit"
        document.forms[0].submit();
    }
</script>
<form action="<%=Request.ServerVariables("SCRIPT_NAME")%>" method="POST">
    <input type="hidden" name="SubmitType" id="SubmitType" />
    <%
    ' Check for form submit
    If Request.Form("SubmitType") = "Refresh" Then Call RefreshForm()
    If Request.Form("SubmitType") = "Submit" Then Call HandleSubmit()
    %>
    <input type="button" value="Submit form" onclick="SubmitForm()" />
</form>

<%
' Subs and functions
Sub HandleSubmit()
    'Handle input e.g. save to db
End Sub

Sub RefreshForm()
'Retrieve input
Dim First, Second, Third
First = Request.Form("First")
Second = Request.Form("Second")
Third = Request.Form("Third")

' Open the DB Conn...
Dim Conn, strDbConn
strDbConn = "YourConnString"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open strDbConn

' Print out dropdowns
Call PrintDropDown "First", " SELECT ID, Label FROM FirstTable ", First ' Print first dropdown
If First <> "" Then Call PrintDropDown "Second", " SELECT ID, Label FROM SecondTable ", Second ' If first selection made print next dropdown
If Second <> "" Then Call PrintDropDown "Third", " SELECT ID, Label FROM ThirdTable ", Third ' If second selection made print next dropdown

'Close DB Conn
Conn.Close
Set Conn = Nothing

End Sub

Sub PrintDropDown(Name, SQL, SelectedValue)
    Dim RS
    Set RS = Conn.Execute(SQL)

    If Not RS.EOF Then
        %>select name="<%=Name%>" onChange="RefreshForm()"><%
        Do While Not RS.EOF
            %><option value="<%=RS(0)%>"  <%=GetSelected(SelectedValue, RS(0) )%>><%=RS(1)%></option><%
            RS.MoveNext
        Loop
        %></select><%
    End If
    Set RS = Nothing
End Sub

Function GetSelected(SelectedID, IDtoCheck)
    If Cstr(SelectedID) = Cstr(IDtoCheck) Then
        GetSelected = "selected=""selected"""
    Else
        GetSelected = ""
    End If
End Function
%>


Hope this helps someone,

Tim

P.S. Haven't really tested it, If you find any errors, let me know I'll fix them.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Dynamic Dropdowns


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT