Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 17th, 2004, 06:27 AM
Registered User
 
Join Date: Dec 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic drop down list

Hi,

I've created a ASP page with dynamic drop-down lists but have a problem for the result, the selections go fine until I want to ask for the result. If I end my selection I want to open a second page that gives me a specific word document based on the criteria I made before
The word document is linked to a hyperlink in the database

I send the code I already have at the end.
the link is http://bamo.dyndns.org/lgr/kookboek.asp

the code:
<%@ Language = VBScript %>
<%Option Explicit%>
<%Response.Buffer = True%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<%
dim strDataPath, strConnectString, objConnection, strWarmofKoud, strGroep, strTitel, objRS, strSelected, strSQL

strWarmofKoud = Request.Form("WarmofKoud")
strGroep = Request.Form("Groep")
strTitel = Request.Form("Titel")

'set connection strings for entire application
strDataPath = server.MapPath("kookboek.mdb")
strConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;"_
            + " Data Source= " & strDataPath & ";"_
            + " Mode=Share Deny None;User Id=admin;PASSWORD=;"

if not IsObject("ojbConnection") then
    set objConnection=Server.CreateObject("ADODB.Connectio n")
    objConnection.ConnectionTimeout = 15
    objConnection.CommandTimeout = 10
    objConnection.Mode = 3 'adModeReadWrite
    if objConnection.state = 0 then
        objConnection.Open strConnectString
    end if
end if

sub makeWarmofKoud()
    if not isObject("objRS") then
        set objRS=Server.CreateObject("ADODB.RecordSet")
    end if
    if objRS.state <> 0 then
        objRS.close
    end if
    strSQL = "SELECT DISTINCT WarmofKoud FROM kookbtabel1 ORDER BY WarmofKoud"
    objRS.open strSQL,objConnection,3,3
    Response.Write("<option></option>" & VBCRLF )
    do while not objRS.EOF
        if objRS("WarmofKoud") = strWarmofKoud then
            strSelected = " Selected "
        else
            strSelected = ""
        end if
        Response.Write("<option" & strSelected & ">" & objRS("WarmofKoud") & "</option>" & VBCRLF )
        objRS.MoveNext
    loop
    objRS.Close
    set objRS=Nothing
end sub

sub makeGroep()
    if strWarmofKoud <> "" then
        if not isObject("objRS") then
            set objRS=Server.CreateObject("ADODB.RecordSet")
        end if
        if objRS.state <> 0 then
            objRS.close
        end if
        strSQL = "SELECT DISTINCT Groep FROM kookbtabel1 WHERE WarmofKoud = '" & strWarmofKoud & "' ORDER BY Groep"
        objRS.Open strSQL,objConnection,3,3
        if objRS.eof then
            Response.Write("<option>Geen Groepen Gevonden</option>")
        else
            Response.Write("<option>Selecteer Groep</option>" & VBCRLF )
            do while not objRS.EOF
                if objRS("Groep") = strGroep then
                    strSelected = " Selected "
                else
                    strSelected = ""
                end if
                Response.Write("<option" & strSelected & ">" & objRS("Groep") & "</option>" & VBCRLF )
                objRS.MoveNext
            loop
        end if
        objRS.Close
        set objRS=Nothing
    else
        Response.Write("<option>Selecteer Warm of Koud eerst</option>")
    end if
end sub

sub makeTitel()
    if strGroep <> "Selecteer Warm of Koud eerst" AND strGroep <> "Selecteer Groep" AND strGroep <>"" then
        if not isObject("objRS") then
            set objRS=Server.CreateObject("ADODB.RecordSet")
        end if
        if objRS.state <> 0 then
            objRS.close
        end if
        strSQL = "SELECT DISTINCT Titel FROM kookbtabel1 WHERE Groep = '" & strGroep & "' ORDER BY Titel"
        objRS.Open strSQL,objConnection,3,3
        if objRS.eof then
            Response.Write("<option>Geen titels gevonden</option>")
        else
            Response.Write("<option>Selecteer Titel</option>" & VBCRLF )
            do while not objRS.EOF
                if objRS("Titel") = strTitel then
                    strSelected = " Selected "
                else
                    strSelected = ""
                end if
                Response.Write("<option" & strSelected & ">" & objRS("Titel") & "</option>" & VBCRLF )
                objRS.MoveNext
            loop
        end if
        objRS.Close
        set objRS=Nothing
    else
        Response.Write("<option>Selecteer eerst een groep</option>")
    end if
end sub

%>

<SCRIPT LANGUAGE=javascript>
<!--

function submitWarmofKoud(){
    var objForm = document.forms[0];
    objForm.elements['Groep'].selectedIndex=0;
    objForm.elements['Titel'].selectedIndex = 0;
    objForm.submit();
}
function submitGroep(){
    var objForm = document.forms[0];
    objForm.elements['Titel'].selectedIndex = 0;
    objForm.submit();
}


function submitForm(){
    var objForm=document.forms[0];
    objForm.action = "http://bamo.dyndns.org/lgr/result1kookboek.asp"
    return true;
}
//-->
</SCRIPT>

</HEAD>
<BODY>
<p align="center"><i><b>Ons Kookboek</b></i></p>
<FORM action="" method=POST id=form1 name=form1 onSubmit="return submitForm()">
<table border="0" width="100%" id="table1">
    <tr>
        <td width="350">Zoekt u een warm of koud gerecht?</td>
        <td> <SELECT name="WarmofKoud" onChange="submitWarmofKoud()">
    <%call makeWarmofKoud%>
</SELECT></td>
    </tr>
    <tr>
        <td>Selecteer de groep waaronder het gerecht valt:</td>
        <td> <SELECT name="Groep" onChange="submitGroep()">
    <%call makeGroep%>
</SELECT></td>
    </tr>
    <tr>
        <td>Selecteer een van de gerechten:</td>
        <td> <SELECT name="Titel">
    <%call makeTitel%>
</SELECT></td>
    </tr>
</table>
<p> </p>
<p><INPUT type="submit" value="Opvragen" id=submit1 name=submit1></p>
</FORM>
</BODY>
<%
objConnection.Close
set objConnection = Nothing
%>

</HTML>



Bart Moons
 
Old December 17th, 2004, 01:30 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Bart,

Your page seems to work fine, what exactly is the problem?

Thanks,

Chris

 
Old December 17th, 2004, 03:54 PM
Registered User
 
Join Date: Dec 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Chris,

The page works fine, the problem is I want to launch a hyperlink that is dependend from the criteria I've made before.
for example: I selected in the first field 'Warm', the second field 'soepen' and the Third field 'wortelsoep' if I click on 'opvragen' I want to open a word document that gives me the recipe for wortelsoep
the problem is the connection to the worddocument. In my database there is a hyperlink to that worddocument but I don't know how to call the worddocument

Bart Moons
 
Old December 20th, 2004, 06:06 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Bart,

You could look up the url of the word document and then Response.Redirect to it.

HTH,

Chris

 
Old December 22nd, 2004, 05:25 AM
Registered User
 
Join Date: Dec 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

but how can i do the response.redirect based on the selection

Bart Moons
 
Old December 22nd, 2004, 05:38 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hey Bart,

You will need to build a query based on the data from your form to select the appropriate word document. How is your database structured?

Cheers,

Chris

 
Old December 22nd, 2004, 05:59 AM
Registered User
 
Join Date: Dec 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My database is actualy one table with the following columns:
warmkoud: text
groep: text
titel: text
recept: hyperlink

Bart Moons
 
Old December 22nd, 2004, 06:11 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

You should be able to run a query something like
Code:
query = "SELECT recept FROM kookbtabel1 WHERE warmkoed = '" & strWarmofKoud & "' " & _
        "AND groep = '" & strGroep & "' AND titel = '" & strTitel & "';"
To get a recordset containing the link from the database.

Then redirect to the link.

Or is it the way the link is stored that is causing problems?

Cheers,

Chris

 
Old December 22nd, 2004, 06:16 AM
Registered User
 
Join Date: Dec 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks
I try it and let you know if it works

Bart Moons
 
Old January 25th, 2005, 10:05 AM
Registered User
 
Join Date: Dec 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

that I have already, when I click the button I get a response.write with the link,
but how can I make it to open the link i place of writing it in the windows
here is the code again with the link
http://bamo.dyndns.org/lgr/kookboek.asp

<%@ Language = VBScript %>
<%Option Explicit%>
<%Response.Buffer = True%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<%
dim strDataPath, strConnectString, objConnection, strWarmofKoud, strGroep, strTitel, strRecept, objRS, strSelected, strSQL

strWarmofKoud = Request.Form("WarmofKoud")
strGroep = Request.Form("Groep")
strTitel = Request.Form("Titel")
strRecept = Request.Form("Recept")

'set connection strings for entire application
strDataPath = server.MapPath("kookboek.mdb")
strConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;"_
            + " Data Source= " & strDataPath & ";"_
            + " Mode=Share Deny None;User Id=admin;PASSWORD=;"

if not IsObject("ojbConnection") then
    set objConnection=Server.CreateObject("ADODB.Connectio n")
    objConnection.ConnectionTimeout = 15
    objConnection.CommandTimeout = 10
    objConnection.Mode = 3 'adModeReadWrite
    if objConnection.state = 0 then
        objConnection.Open strConnectString
    end if
end if

sub makeWarmofKoud()
    if not isObject("objRS") then
        set objRS=Server.CreateObject("ADODB.RecordSet")
    end if
    if objRS.state <> 0 then
        objRS.close
    end if
    strSQL = "SELECT DISTINCT WarmofKoud FROM kookbtabel1 ORDER BY WarmofKoud"
    objRS.open strSQL,objConnection,3,3
    Response.Write("<option></option>" & VBCRLF )
    do while not objRS.EOF
        if objRS("WarmofKoud") = strWarmofKoud then
            strSelected = " Selected "
        else
            strSelected = ""
        end if
        Response.Write("<option" & strSelected & ">" & objRS("WarmofKoud") & "</option>" & VBCRLF )
        objRS.MoveNext
    loop
    objRS.Close
    set objRS=Nothing
end sub

sub makeGroep()
    if strWarmofKoud <> "" then
        if not isObject("objRS") then
            set objRS=Server.CreateObject("ADODB.RecordSet")
        end if
        if objRS.state <> 0 then
            objRS.close
        end if
        strSQL = "SELECT DISTINCT Groep FROM kookbtabel1 WHERE WarmofKoud = '" & strWarmofKoud & "' ORDER BY Groep"
        objRS.Open strSQL,objConnection,3,3
        if objRS.eof then
            Response.Write("<option>Geen Groepen Gevonden</option>")
        else
            Response.Write("<option>Selecteer Groep</option>" & VBCRLF )
            do while not objRS.EOF
                if objRS("Groep") = strGroep then
                    strSelected = " Selected "
                else
                    strSelected = ""
                end if
                Response.Write("<option" & strSelected & ">" & objRS("Groep") & "</option>" & VBCRLF )
                objRS.MoveNext
            loop
        end if
        objRS.Close
        set objRS=Nothing
    else
        Response.Write("<option>Selecteer Warm of Koud eerst</option>")
    end if
end sub

sub makeTitel()
    if strGroep <> "Selecteer Warm of Koud eerst" AND strGroep <> "Selecteer Groep" AND strGroep <>"" then
        if not isObject("objRS") then
            set objRS=Server.CreateObject("ADODB.RecordSet")
        end if
        if objRS.state <> 0 then
            objRS.close
        end if
        strSQL = "SELECT DISTINCT Titel FROM kookbtabel1 WHERE Groep = '" & strGroep & "' ORDER BY Titel"
        objRS.Open strSQL,objConnection,3,3
        if objRS.eof then
            Response.Write("<option>Geen titels gevonden</option>")
        else
            Response.Write("<option>Selecteer Titel</option>" & VBCRLF )
            do while not objRS.EOF
                if objRS("Titel") = strTitel then
                    strSelected = " Selected "
                else
                    strSelected = ""
                end if
                Response.Write("<option" & strSelected & ">" & objRS("Titel") & "</option>" & VBCRLF )
                objRS.MoveNext
            loop
        end if
        objRS.Close
        set objRS=Nothing
    else
        Response.Write("<option>Selecteer eerst een groep</option>")
    end if
end sub

sub makeRecept()
    if strTitel <> "Selecteer groep eerst" AND strTitel <> "Selecteer Titel" AND strTitel <>"" then
        if not isObject("objRS") then
            set objRS=Server.CreateObject("ADODB.RecordSet")
        end if
        if objRS.state <> 0 then
            objRS.close
        end if
        strSQL = "SELECT DISTINCT Recept FROM kookbtabel1 WHERE Titel = '" & strTitel & "' ORDER BY Recept"
        objRS.Open strSQL,objConnection,3,3
        if objRS.eof then
            Response.Write("<option>Geen Recept gevonden</option>")
        else
            Response.Write("<option>Selecteer Recept</option>" & VBCRLF )
            do while not objRS.EOF
                if objRS("Recept") = strRecept then
                    strSelected = " Selected "
                else
                    strSelected = ""
                end if
                Response.Write("<option" & strSelected & ">" & objRS("Recept") & "</option>" & VBCRLF )
                objRS.MoveNext
            loop
        end if
        objRS.Close
        set objRS=Nothing
    else
        Response.Write("<option>Selecteer eerst een groep</option>")
    end if
end sub


%>

<SCRIPT LANGUAGE=javascript>
<!--

function submitWarmofKoud(){
    var objForm = document.forms[0];
    objForm.elements['Groep'].selectedIndex=0;
    objForm.elements['Titel'].selectedIndex = 0;
    objForm.submit();
}
function submitGroep(){
    var objForm = document.forms[0];
    objForm.elements['Titel'].selectedIndex = 0;
    objForm.submit();
}


function submitForm(){
    var objForm=document.forms[0];
    objForm.Action['Recept'].selectedIndex = 0;
    objForm.submit();
    return true;
}
//-->
</SCRIPT>

</HEAD>
<BODY>
<p align="center"><i><b>Ons Kookboek</b></i></p>
<FORM action="" method=POST id=form1 name=form1 onSubmit="return submitForm()">
<table border="0" width="100%" id="table1">
    <tr>
        <td width="350">Zoekt u een warm of koud gerecht?</td>
        <td> <SELECT name="WarmofKoud" onChange="submitWarmofKoud()">
    <%call makeWarmofKoud%>
</SELECT></td>
    </tr>
    <tr>
        <td>Selecteer de groep waaronder het gerecht valt:</td>
        <td> <SELECT name="Groep" onChange="submitGroep()">
    <%call makeGroep%>
</SELECT></td>
    </tr>
    <tr>
        <td>Selecteer een van de gerechten:</td>
        <td> <SELECT name="Titel">
    <%call makeTitel%>
</SELECT></td>
    </tr>
</table>
<p>&nbsp;</p>
<p><INPUT type="submit" value="Opvragen" id=submit1 name=submit1></p>
    <%call makeRecept%>
</FORM>
</BODY>
<%
objConnection.Close
set objConnection = Nothing
%>

</HTML>

Bart Moons





Similar Threads
Thread Thread Starter Forum Replies Last Post
hyperlinks in a dynamic drop down list matti ASP.NET 1.0 and 1.1 Basics 1 October 15th, 2008 10:31 AM
Drop down list carumuga Classic ASP Basics 1 February 6th, 2007 02:37 PM
drop down list values based on another drop down noor ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2005 09:57 AM
Dynamic drop-down list lucian Dreamweaver (all versions) 2 July 8th, 2004 05:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.