40 users online (0 members and 40 guests)  

  Results 1 to 2 of 2


  1. more imagemap and iframe troubles    Forum: HTML Forum
    Replies: 2
  2. Replies: 1
  3. Replies: 4
  4. Replies: 1
  5. Form Handling Script for 'Tell A Friend' Form    Forum: Javascript Forum
    Replies: 1
  1. #1
    danfossdave's Avatar
    New User

    Join Date
    Mar 2004

    Question ASP Imagemap form

    Help please.

    I am a newbie to ASP. I have been able to manipulate some code from an "ASP Sample code" site that allows me to have users query a database by typing into a text box. I am looking for a way to have a user submit a database query by selecting an area from a client side imagemap. (i.e. click on your state to get a list of authorized dealers in your state) What I have works now, but the user has to type the name of the state.
    This is the code I have borrowed and modified:
    I am assuming that I need to edit the form section of this code (in bold) - but I don't know what the modifications should look like. Any help would be appreciated.

    ' Declare our variables... always good practice!
    Dim strURL ' The URL of this page so the form will work
    ' no matter what this file is named.

    Dim cnnSearch ' ADO connection
    Dim rstSearch ' ADO recordset
    Dim strDBPath ' path to our Access database (*.mdb) file

    Dim strSQL ' The SQL Query we build on the fly
    Dim strSearch ' The text being looked for

    ' Retreive the URL of this page from Server Variables
    strURL = Request.ServerVariables("URL")

    ' Retreive the term being searched for. I'm doing it on
    ' the QS since that allows people to bookmark results.
    ' You could just as easily have used the form collection.
    strSearch = Request.QueryString("search")

    ' Since I'm doing this all in one page I need to see if anyone
    ' has searched for something. If they have we hit the DB.
    ' O/W I just show the search form and quit.


    <font face="Arial, Helvetica, sans-serif" size="+2">
    Please type the full name of your Province or State</p>
    <form action="<%= strURL %>" method="get">
    <input name="search" value="<%= strSearch %>" />
    <input type="submit" />
    If strSearch <> "" Then
    ' MapPath of virtual database file path to a physical path.
    ' If you want you could hard code a physical path here.
    strDBPath = Server.MapPath("usrepbyregion.mdb")

    ' Create an ADO Connection to connect to the sample database.
    ' We're using OLE DB but you could just as easily use ODBC or a DSN.
    Set cnnSearch = Server.CreateObject("ADODB.Connection")

    ' This line is for the Access sample database:
    cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"

    ' We're actually using SQL Server so we use this line instead:
    'cnnSearch.Open "Provider=SQLOLEDB;Data Source=;" _
    '& "Initial Catalog=samples;User Id=samples;Password=password;" _
    '& "Connect Timeout=15;Network Library=dbmssocn;"

    ' Build our query based on the input.
    strSQL = "SELECT * FROM main WHERE region LIKE '%" & Replace(strSearch, "'", "''") & "%' "

    ' Execute our query using the connection object. It automatically
    ' creates and returns a recordset which we store in our variable.
    Set rstSearch = cnnSearch.Execute(strSQL)

    ' Display a table of the data in the recordset. We loop through the
    ' recordset displaying the fields from the table and using MoveNext
    ' to increment to the next record. We stop when we reach EOF.
    ' For fun I'm combining some fields and showing you can do more then
    ' just spit out the data in the form it is in in the table.
    <table width="600">
    Do While Not rstSearch.EOF
    <td><font face="Arial, Helvetica, sans-serif" color="ff0000"><b><%= rstSearch.Fields("region").Value %></b></font></td>
    <td><font face="Arial, Helvetica, sans-serif">Product Line: <%= rstSearch.Fields("product_line").Value %></font></td>
    <td><b><a href="http://<%= rstSearch.Fields("website").Value %>"><font face="Arial, Helvetica, sans-serif"><%= rstSearch.Fields("name").Value %></font></a></b></td>
    <td><font face="Arial, Helvetica, sans-serif"><%= rstSearch.Fields("address1").Value %></font></td>
    <td><font face="Arial, Helvetica, sans-serif"><%= rstSearch.Fields("city").Value %></font>&nbsp
    <font face="Arial, Helvetica, sans-serif"><%= rstSearch.Fields("state").Value %></font>&nbsp<font face="Arial, Helvetica, sans-serif"><%= rstSearch.Fields("zip_code").Value %></font></td>
    <td><font face="Arial, Helvetica, sans-serif">Phone: <%= rstSearch.Fields("telephone").Value %></font></td>
    <td><font face="Arial, Helvetica, sans-serif">Fax: <%= rstSearch.Fields("fax").Value %></font></td>
    <td height="17"><font face="Arial, Helvetica, sans-serif">Email:<a href="mailto:<%= rstSearch.Fields("email").Value %>">
    <%= rstSearch.Fields("email").Value %></font></a> </td>
    <td height="6"><font face="Arial, Helvetica, sans-serif">Website:<a href="http://<%= rstSearch.Fields("url").Value %>">
    <%= rstSearch.Fields("url").Value %></font></a><br>

    ' Close our recordset and connection and dispose of the objects
    Set rstSearch = Nothing
    Set cnnSearch = Nothing
    End If

    ' That's all folks! See it's really not all that hard.

  2. #2
    QuietDean's Avatar

    Join Date
    Oct 2000
    Bournemouth, UK
    Your code is good. All you need is the imagemap, and to slightly amend your code to pickup the coords and process them instead.

    If your not familiar with imagemaps, heres an intro - http://hoohoo.ncsa.uiuc.edu/docs/tutorials/imagemapping.html
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

Tags for this Thread