• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

Bookmarkable Anchor

Hi,

The following code is working 100%.  But,  it creates an anchor each time a search is done.

Suppose I searched for a CustomerID BLONP it finds it and creates a temporay anchor that can not be bookmarked.

How to make the page bookmarkable so next time I open it,  it will go to that ID BLONP which I searched for.


<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body onLoad="window.navigate('IDHL6.asp#FoundID');">
<form method="POST" action="IDHL6.asp#FoundID">
  <p>Country: <input type="text" name="CustomerID" size="20"></p>
  <p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2">
  <a href="IDHL5.asp">All</a></p>
</form>
<BR>
<%
last_visable_record=23
CustID=request.form("CustomerID")
Set MyConn = Server.CreateObject("ADODB.Connection")
MdbFilePath = Server.MapPath("fpdb/Northwind.mdb")
MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
SQL_query = "SELECT * FROM Customers"
Set RS = MyConn.Execute(SQL_query)
%>

 <table align="center" border="1" cellpadding="1" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111" width="500" id="AutoNumber1">
  <tr>
    <td align="center" bgcolor="#000080"><B><font color="#FFFFFF">Customer ID</font></B></td>
    <td align="center" bgcolor="#000080"><B><font color="#FFFFFF">Contact Name</font></B></td>
    <td align="center" bgcolor="#000080"><B><font color="#FFFFFF">Contact Title</font></B></td>
    <td align="center" bgcolor="#000080"><B><font color="#FFFFFF">Country</font></B></td>

  </tr>
<%
function countMatches(sSearchParam, activeConnection)
  Dim lRetCount
  lRetCount = ""
  if len(sSearchParam)>0 then
    Dim rsCount
    Dim sSQL
    sSQL = "SELECT COUNT(1) AS CountResults FROM Customers WHERE CustomerID='"&replace(sSearchParam, "'", "''")&"'"
    set rsCount = server.createobject("adodb.recordset")
    rsCount.open sSQL, activeConnection, 1, 3, 1
    lRetCount = rsCount.fields("CountResults")
    rsCount.close
    set rsCount=nothing
  end if
  countMatches = lRetCount
end function
%>


<%
Dim sBGColor
  Dim sAnchor
 if len(request("CustomerID"))>0 then
 if countMatches(request("CustomerID"), MyConn)=0 then
    response.write "There were no records returned by your search. Please try again."
 end if
end if

    do WHILE NOT RS.EOF
      count = count + 1
      sAnchor = "" 
      if UCASE(trim(CustID)) = UCASE(trim(RS("CustomerID"))) then
        sBGColor = " bgcolor=yellow"
        if count > last_visable_record then
          sAnchor = "<A NAME=""FoundID""></A>"
          end if
      else
        sBGColor = ""
      end if
     
%>
  <tr<%=sBGColor%>>
        <td align="left"><%=sAnchor%>&nbsp;<% =RS("CustomerID")%>&nbsp;</td>
        <td align="left">&nbsp;<% =RS("ContactName")%>&nbsp;</td>
        <td align="left">&nbsp;<% =RS("ContactTitle")%>&nbsp;</td>
        <td align="left">&nbsp;<% =RS("Country")%>&nbsp;</td>
      </tr>
<%
      RS.MoveNext
    loop
%>


</table>
</body>

</html>


Thanks
0
hhammash
Asked:
hhammash
  • 2
  • 2
1 Solution
 
mk_bCommented:
Try changing the form from a POST to a GET and then where ever you got request.form to Request.Querystring

so when the person bookmarks the page it will be IDHL6.asp?CustomerID=what#FoundID

that way when the come back to the site the search will be run automaticly and the page will jusp to the right place..

in theory of course..

../mk

Try this it worked for me...


<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body onload="window.location='#FoundID';">
<form method="get" action="IDHL5.asp#FoundID">
  <p>Country: <input type="text" name="CustomerID" size="20"></p>
  <p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2">
  <input type="hidden" name="anchor" value="#FoundID"
  <a href="IDHL5.asp">All</a></p>
</form>
<BR>
<%
last_visable_record=23
CustID=request("CustomerID")
Set MyConn = Server.CreateObject("ADODB.Connection")
MdbFilePath = Server.MapPath("fpdb/Northwind.mdb")
MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
SQL_query = "SELECT * FROM Customers"
Set RS = MyConn.Execute(SQL_query)
%>

 <table align="center" border="1" cellpadding="1" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111" width="500" id="AutoNumber1">
  <tr>
    <td align="center" bgcolor="#000080"><B><font color="#FFFFFF">Customer ID</font></B></td>
    <td align="center" bgcolor="#000080"><B><font color="#FFFFFF">Contact Name</font></B></td>
    <td align="center" bgcolor="#000080"><B><font color="#FFFFFF">Contact Title</font></B></td>
    <td align="center" bgcolor="#000080"><B><font color="#FFFFFF">Country</font></B></td>

  </tr>
<%
function countMatches(sSearchParam, activeConnection)
  Dim lRetCount
  lRetCount = ""
  if len(sSearchParam)>0 then
    Dim rsCount
    Dim sSQL
    sSQL = "SELECT COUNT(1) AS CountResults FROM Customers WHERE CustomerID='"&replace(sSearchParam, "'", "''")&"'"
    set rsCount = server.createobject("adodb.recordset")
    rsCount.open sSQL, activeConnection, 1, 3, 1
    lRetCount = rsCount.fields("CountResults")
    rsCount.close
    set rsCount=nothing
  end if
  countMatches = lRetCount
end function
%>


<%
Dim sBGColor
  Dim sAnchor
 if len(request("CustomerID"))>0 then
 if countMatches(request("CustomerID"), MyConn)=0 then
    response.write "There were no records returned by your search. Please try again."
 end if
end if

    do WHILE NOT RS.EOF
      count = count + 1
      sAnchor = "" 
      if UCASE(trim(CustID)) = UCASE(trim(RS("CustomerID"))) then
        sBGColor = " bgcolor=yellow"
        if count > last_visable_record then
          sAnchor = "<A NAME=""FoundID""></A>"
          end if
      else
        sBGColor = ""
      end if
     
%>
  <tr<%=sBGColor%>>
        <td align="left"><%=sAnchor%>&nbsp;<% =RS("CustomerID")%>&nbsp;</td>
        <td align="left">&nbsp;<% =RS("ContactName")%>&nbsp;</td>
        <td align="left">&nbsp;<% =RS("ContactTitle")%>&nbsp;</td>
        <td align="left">&nbsp;<% =RS("Country")%>&nbsp;</td>
      </tr>
<%
      RS.MoveNext
    loop
%>


</table>
</body>

</html>
0
 
hhammashAuthor Commented:
Hi Mk,

It is working fine with no problem, but I will show you what appears on the addres bar:

http://residenc-9c69f0/Pictures4/BookMarkableAnchor.asp?CustomerID=Consh&B1=Submit&anchor=%23FoundID#FoundID

Why is the B1=Submit (the form button is mentioend)?
Why #FoundID is mentioned.  The correct URL which is enough is
http://residenc-9c69f0/Pictures4/BookMarkableAnchor.asp?CustomerID=Consh

Why is this addition?
&B1=Submit&anchor=%23FoundID#FoundID

How can the Code generate this URL only:
http://residenc-9c69f0/Pictures4/BookMarkableAnchor.asp?CustomerID=Consh


Thank you
hhammash
0
 
mk_bCommented:
when you use "GET" in a form it passes all the form ellements so it will pass the button with it?

you need the anchor=FoundID#FoundID so that it will just to the right place?

I dont know if you are going to be able to get the url to look the way you want? If someone bookmarks the page they will see the <title>My Page</title> anyway...

../mk
0
 
hhammashAuthor Commented:
Thank you MK_b
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now