Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect with picklist problem

Status
Not open for further replies.

GROOVYHEN

Programmer
Apr 19, 2004
12
GB
I want to create a picklist from fields in a database. The two db fields are Code and Pages, and both display the exact same information - the names of web pages under each column:
code | pages
----------------------
home | home
links | links
site info | site info

Depending on which option the user selects, then the user will be redirected to that page e.g. if links is clicked, then obviously they would go to the links page. At the moment, I've only got it working for two options: either click home and go to alpha, or click something else and go to beta. I want it so that every option leads to a different page. I think that I may need to just expand the if...else bit of my code, but I'm not entirely sure as to how I could do this. I've tried 'case' as well and had no luck.

Here's my code (what is written in on alpha.htm and beta.htm is irrelevant):

<%
strconn = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("database/ambvibdb.mdb")
set conn = server.createobject("adodb.connection")
conn.open strconn

dim locpage
locpage = request.form("gotopage")

If locpage <>"" then
If locpage = "Home" then
Response.redirect("alpha.htm")
else
Response.redirect("beta.htm")
end if
end if


'connect to database

SQLQuery = "Select * from Pages where Pages = '"
sqlquery = sqlquery & loccust & "'"
Set RSPage = Conn.Execute(SQLQuery)%>


<html>

<head>
</head>

<body>

<form action="pickithome.asp" onSubmit="return isReady(this)" METHOD=post name="form1" >

<table>
<TD width="1"> <select size=1 name="gotopage">
<%
SQLQuery = "Select * from Pages"
Set RSPage = Conn.Execute(SQLQuery)

Do While Not RSPage.Eof
if rspage("Code") = "Home" then
response.write("<option value=" & RSPage("Code") & " selected>" & RSPage("Pages") & "</option>")
else
response.write("<option value=" & RSPage("Code") & ">" & RSPage("Pages") & "</option>")
end if
RSPage.Movenext
Loop

SET RSPage = NOTHING
SET Conn = NOTHING
%>
</select></TD>
<tr>
<td width = "118" height="50"><input TYPE="Submit" VALUE="submit" id=Submit1 name=Submit1></td>
<td width="1" height="50"><input TYPE="Reset" VALUE="Clear Details" id=Reset1 name=Reset1> </td>
</tr>
</table>
</form>
</body>

</html>

Can anyone alter this code to help me out?
 
you have 2 easy options here, if you want the redirect immediate, use javascript and there's hoards of references on javascript drop down redirects online.

second option to avoid having to recode your script everytime you need to add a new link/page/redirect is make the value of the dropdown = location and use simple id's to view like

<select name="redirectme">
<option value="/">Home</option>
<option value="/faqs/faq.html">Faq</option>
etc...

then in the page that accepts/redirects, if request("redirectme") <> "" then response.redirect(request("redirectme"))
 
I wouldn't want to use javascript.

But does your second solution make use of the database.

If anyone replies, please could they just alter my complete code? I need to get a full understanding.
 
could only alter/finish your code if the page location was in the DB and i had a field name for it, like change the value in the DB of "CODE" to the actual location of the page, like /faq/faq.html or and so on, if you do that the only part of your code you'd need to change is :
Code:
locpage = request.form("gotopage") 

If locpage <>"" then
    If locpage = "Home" then
        Response.redirect("alpha.htm")
    else
        Response.redirect("beta.htm")
    end if
end if

Change it to :

Code:
locpage = request.form("gotopage") 
If locpage <>"" then Response.redirect(locpage)


AND

Code:
<table>
      <TD width="1"> <select size=1 name="gotopage">
          <% 
SQLQuery = "Select * from Pages"
Set RSPage = Conn.Execute(SQLQuery)

Do While Not RSPage.Eof
if rspage("Code") = "Home" then
    response.write("<option value=" & RSPage("Code") & " selected>" & RSPage("Pages") & "</option>")
else
    response.write("<option value=" & RSPage("Code") & ">" & RSPage("Pages") & "</option>")
end if
    RSPage.Movenext
Loop

SET RSPage = NOTHING
SET Conn = NOTHING
%>
        </select></TD>

Change to :
Code:
<table>
      <TD width="1"> <select size=1 name="gotopage">
          <% 
SQLQuery = "Select * from Pages"
Set RSPage = Conn.Execute(SQLQuery)

Do While Not RSPage.Eof
if rspage("Code") = "Home" then
    response.write("<option value=" & Server.HTMLEncode(RSPage("Code")) & " selected>" & RSPage("Pages") & "</option>")
else
    response.write("<option value=" & Server.HTMLEcode(RSPage("Code")) & ">" & RSPage("Pages") & "</option>")
end if
    RSPage.Movenext
Loop

SET RSPage = NOTHING
SET Conn = NOTHING
%>
        </select></TD>
the second change is to avoid issues with special characters
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top