Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ASP / Database Access / August 2008



Tip: Looking for answers? Try searching our database.

Getting info from Drop Down

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Emma - 01 Aug 2008 20:38 GMT
I'm trying to use a drop down list for the user to select an entery which
will goo back to the database and grabs what the user selects then outputs a
list using ConnectDatabase.asp. The problem is I don't know how to make input
tags for a drop down? Hi I have a html file with the following:

<form name "input" action "ConnectDatabase.asp" method "get">

<select>BedroomSize
               <optgroup label="Bedroom Size">  
                       <option value = "Bachelor"> Bachelor </option>
                       <option value = "Room / Share"> Room / Share
</option>                                          
                       <option value = "1"> 1</option>
                       <option value = "2"> 2 </option>
                       <option value = "3">3 </option>
                       <option value = "4"> 4 </option>
                       <option value = "5+"> 5+ </option>
         
               </optgroup>
          </select>
  <input type="submit" value="Submit">
     </form>

And I have an .asp file with the following
<%
Option Explicit
Response.Expires = -1000

Dim oConn
Dim oRS
Dim sSQL
Dim sColor

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
Server.MapPath("\EmilyLeeParsons\db\HHCDataBase.mdb"))

sSQL = "SELECT DatePosted, Area, NearestIntersection, HousingType,
BedroomSize, Rent, Details FROM TblHousing"
Set oRS = oConn.Execute(sSQL)

    Response.Write("<table border=1 cellpadding=1 cellspacing=1
style='font-family:arial; font-size:10pt;'>")
    Response.Write("<tr bgcolor=black style='color:white;'><td>DatePosted</td>")
    Response.Write("<td>Area</td>")
    Response.Write("<td align=right>NearestIntersection</td>")
       Response.Write("<td>HousingType</td>")
    Response.Write("<td align=right>BedroomSize</td>")
       Response.Write("<td align=right>Rent</td>")
    Response.Write("<td>Details</td></tr>")

sColor = "white"

Do While NOT oRS.EOF

    If sColor = "silver" Then
        sColor = "white"
    Else
        sColor = "silver"
    End If
 
    Response.Write("<tr bgcolor='" & sColor & "'>")
    Response.Write("<td>" & oRS("DatePosted").Value & "</td>")
    Response.Write("<td>" & oRS("Area").Value & "</td>")
       Response.Write("<td>" & oRS("NearestIntersection").Value & "</td>")
    Response.Write("<td>" & oRS("HousingType").Value & "</td>")
       Response.Write("<td>" & oRS("BedroomSize").Value & "</td>")
    Response.Write("<td align=right>$" & oRS("Rent").Value & "</td>")
    Response.Write("<td align=right>" & oRS("Details").Value & "</td></tr>")
   
    oRS.MoveNext

Loop

    Response.Write("</table><br><br>")

oConn.Close
Set oRS = Nothing
Set oConn = Nothing

%>


How do I get the information from the html page drop down to the asp page?
Old Pedant - 01 Aug 2008 23:22 GMT
> I'm trying to use a drop down list for the user to select an entery which
> will goo back to the database and grabs what the user selects then outputs a
> list using ConnectDatabase.asp. The problem is I don't know how to make input
> tags for a drop down

You just have to *NAME* the <select> (same as any other form field).

Example (and look at the first <option> that I added):

     <select name="BedroomSize">
     <optgroup label="Bedroom Size">
     <option value=""> Any Size </option>
     <option value = "Bachelor"> Bachelor </option>
      ... rest same ...
      </select>

And how about adding this:
      Show listings in what order?
      <select name="orderby">
      <option value="DatePosted DESC"> Date posted, recent first
      <option value="DatePosted ASC"> Date posted, oldest first
      <option value="Rent DESC"> Rent, highest first
      <option value="Rent ASC"> Rent, lowest first
      </select>

And then, in the page you post the form to, do this:

<%
... code ...

Dim reqBedroomSize, where, orderby
reqBedroomSize = Trim("" & Request("BedroomSize") )
where = ""
If reqBedroomSize <> "" Then
   where = " WHERE BedroomSize = '" & Replace(reqBedroomSize, "'", "''" ) &
"' "
End If
' note that if user selected "any" for size, then there won't be a WHERE
clause

orderby = Trim( Request("orderby") )

sSQL = "SELECT DatePosted, Area, NearestIntersection, HousingType, " _
       &            " BedroomSize, Rent, Details " _
       & " FROM TblHousing " _
       & where _
       & " ORDER BY [" & Replace(orderby, "'", "''") & "]"
... rest same ...
Emma - 06 Aug 2008 20:29 GMT
Thankyou so much, it's really simple and helpful!

> > I'm trying to use a drop down list for the user to select an entery which
> > will goo back to the database and grabs what the user selects then outputs a
[quoted text clipped - 44 lines]
>         & " ORDER BY [" & Replace(orderby, "'", "''") & "]"
> ... rest same ...
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.