CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   ASP (http://www.codingforums.com/forumdisplay.php?f=8)
-   -   Send value from Drop Down Selection (http://www.codingforums.com/showthread.php?t=289775)

stanleyc 03-14-2013 03:13 AM

Send value from Drop Down Selection
 
I have a Drop Down list populated from an SQL DB and then a submit button to send the selection as a URL Parameter to get details on the next ASP page. I need to be able to send an ID with that in the URL parameter based on the selection I made. I have tried using a hidden field but the ID that gets sent is just the first one in the list and I need it to be the ID in the SQL table of what was selected in the drop down.

ANY help will be appreciated.

Thanks
Chris

Old Pedant 03-14-2013 06:19 AM

Show your code as you have it now.

Especially how you populate the <select>.

It's really hard to guess what you need from just that description. Might be trivial answer; might be tough.

stanleyc 03-14-2013 01:27 PM

Thanks for the reply.....I realize this is crappy dreamweaver code but it's the only way I know how to do this stuff sorry.....

Landname is the dropdown field I have and I select one of those and then click submit to get the detail for that Landname. I need to send over the ID that's in the same table for that selection in the URL Parameter on the detail page.

Thanks

Code:

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/Landmarks.asp" -->
<%
Dim RSLandmarks
Dim RSLandmarks_cmd
Dim RSLandmarks_numRows

Set RSLandmarks_cmd = Server.CreateObject ("ADODB.Command")
RSLandmarks_cmd.ActiveConnection = MM_Landmarks_STRING
RSLandmarks_cmd.CommandText = "SELECT * FROM dbo.tblLandmark ORDER BY LandName ASC"
RSLandmarks_cmd.Prepared = true

Set RSLandmarks = RSLandmarks_cmd.Execute
RSLandmarks_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body,td,th {
        color: #0FF;
}
body {
        background-color: #000;
}
.Fonts {
        font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
}
.Fonts2 {
        color: #FFF;
}
</style>
</head>

<body class="Fonts">
<h2>Landmark Search
</h2>
<p class="Fonts2">Landmark Name:</p>
<form id="form1" name="form1" method="get" action="LandmarkInfo.asp">
  <p>
    <label for="Landname"></label>
    <select name="Landname" id="Landname">
      <option value=""></option>
      <%
While (NOT RSLandmarks.EOF)
%>
      <option value="<%=(RSLandmarks.Fields.Item("LandName").Value)%>"><%=(RSLandmarks.Fields.Item("LandName").Value)%></option>
      <%
  RSLandmarks.MoveNext()
Wend
If (RSLandmarks.CursorType > 0) Then
  RSLandmarks.MoveFirst
Else
  RSLandmarks.Requery
End If
%>
    </select>
  </p>
  <p>
    <input type="submit" />
    <input type="reset" name="Reset" id="Reset" value="Reset" />
  </p>
</form>
</body>
</html>
<%
RSLandmarks.Close()
Set RSLandmarks = Nothing
%>


Old Pedant 03-14-2013 08:26 PM

Well, you didn't say what the name of your "ID" field is, in the DB table.

So I have just called it ID. If it is something else, just change then names as shown in red.
Code:

<%@LANGUAGE="VBSCRIPT"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search for Landmarks</title>
<style type="text/css">
body,td,th {
        color: #0FF;
}
body {
        background-color: #000;
}
.Fonts {
        font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
}
.Fonts2 {
        color: #FFF;
}
</style>
</head>

<body class="Fonts">
<h2>Landmark Search
</h2>
<p class="Fonts2">Landmark Name:</p>
<form name="form1" method="get" action="LandmarkInfo.asp">
  <p>
    <select name="Landname">
      <option value="">--choose one--</option>
<%
<!--#include file="Connections/Landmarks.asp" -->
<%
Set conn = Server.CreateObject ("ADODB.Connection")
conn.Open MM_Landmarks_STRING
SQL = "SELECT ID, LandName FROM dbo.tblLandmark ORDER BY LandName ASC"

Set RS = conn.Execute( SQL )

Do Until RS.EOF
    id = RS("ID")
    name = RS("LandName")
%>
      <option value="<%=id & "$$" & name%>"><%=name%></option>
<%
    RS.MoveNext()
Loop
RS.Close
Conn.Close
%>
    </select>
  </p>
  <p>
    <input type="submit" />
    <input type="reset" name="Reset" id="Reset" value="Reset" />
  </p>
</form>
</body>
</html>

Now, that means that when this page is submitted to your "LandmarkInfo.asp" page, you will be getting something like
Code:

    371$$Washington Monument
when you use code such as
Code:

    landmark = Request.QueryString("landname")
So you will want to separate the ID from the name using code something like this:
Code:

    parts = Split( Trim( Request("landname") ), "$$" )
    id = CLNG(parts(0))
    landmarke = parts(1)


stanleyc 03-15-2013 02:16 AM

OK, I have gotten the data I need in the string but I can't get it to show properly in the link. I didn't understand the last section where I would do that. Here's what I've done, I'm not sure if I'm close to correct since it strays away from your initial code a little bit.

Here's the current code I have for the string:
Code:

<option value="<%=name & id%>"><%=name%></option>
Which brings me back this:
LandmarkInfo.asp?Landname=WASHINGTONMONUMENT5864

All I need is the &ID=5864 to be there and it will be good but I didn't understand where that code went to accomplish that??

Thanks

Chris

Old Pedant 03-15-2013 06:19 AM

NO NO NO...

You need SOME KIND OF DELIMITER between the name and ID.

That's why i *CAREFULLY* used
Code:

<option value="<%=id & "$$" & name>"><%=name%></option>
DO IT LIKE THAT.

Then show me your code for the LandmarkInfo.asp page, if you didn't understand the rest of what I was saying.

stanleyc 03-15-2013 04:33 PM

OK, I got your initial line back in there.....here's the code for the landmarkinfo.asp:

Code:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/Landmarks.asp" -->
<%
Dim RSLandmarks__MMColParam
RSLandmarks__MMColParam = "1"
If (Request.QueryString("LandName") <> "") Then
  RSLandmarks__MMColParam = Request.QueryString("LandName")
End If
%>
<%
Dim RSLandmarks
Dim RSLandmarks_cmd
Dim RSLandmarks_numRows

Set RSLandmarks_cmd = Server.CreateObject ("ADODB.Command")
RSLandmarks_cmd.ActiveConnection = MM_Landmarks_STRING
RSLandmarks_cmd.CommandText = "SELECT * FROM dbo.tblLandmark WHERE LandName = ?"
RSLandmarks_cmd.Prepared = true
RSLandmarks_cmd.Parameters.Append RSLandmarks_cmd.CreateParameter("param1", 200, 1, 100, RSLandmarks__MMColParam) ' adVarChar

Set RSLandmarks = RSLandmarks_cmd.Execute
RSLandmarks_numRows = 0
%>
<%
Dim RSLandContacts__MMColParam
RSLandContacts__MMColParam = "1"
If (Request.QueryString("IDX") <> "") Then
  RSLandContacts__MMColParam = Request.QueryString("IDX")
End If
%>
<%
Dim RSLandContacts
Dim RSLandContacts_cmd
Dim RSLandContacts_numRows

Set RSLandContacts_cmd = Server.CreateObject ("ADODB.Command")
RSLandContacts_cmd.ActiveConnection = MM_Landmarks_STRING
RSLandContacts_cmd.CommandText = "SELECT * FROM dbo.tblLandmarkContacts WHERE FromID = ?"
RSLandContacts_cmd.Prepared = true
RSLandContacts_cmd.Parameters.Append RSLandContacts_cmd.CreateParameter("param1", 5, 1, -1, RSLandContacts__MMColParam) ' adDouble

Set RSLandContacts = RSLandContacts_cmd.Execute
RSLandContacts_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body {
        background-color: #000;
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        color: #0FF;
}
.Fonts {
        font-size: 24px;
}
OtherFonts {
        color: #FF0;
}
.Data2 {
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        font-size: 10px;
        color: #FFF;
        text-align: left;
}
.Fonts2 {
        color: #FF0;
        font-size: 12px;
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        text-align: left;
}
.Fonts2Heading {
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        color: #FF0;
}
.Fonts table tr td .Fonts2Heading .Fonts2 .Fonts2Heading {
        font-weight: bold;
}
.Data {
        font-size: 12px;
        color: #FFF;
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        text-align: left;
}
.Fonts #form1 table {
        text-align: left;
        font-size: 10px;
}
</style>
</head>

<body class="Fonts">
<table width="100%" border="0">
  <tr>
    <td><div align="center">Landmark Info Display</div></td>
  </tr>
</table>
<p>&nbsp;</p>
<form id="form1" name="form1" method="get" action="">
<table width="100%" border="0" align="center">
    <tr>
      <td width="64%"><span class="Fonts2"><%=(RSLandmarks.Fields.Item("LandName").Value)%></span></td>
    </tr>
    <tr>
      <td class="Data"><span class="Data2"><%=(RSLandmarks.Fields.Item("StNumber").Value)%> <%=(RSLandmarks.Fields.Item("Dir").Value)%> &nbsp; <%=(RSLandmarks.Fields.Item("Address").Value)%></span></td>
    </tr>
    <tr>
      <td class="Data"><span class="Fonts"><span class="Fonts"><span class="Fonts2">CONTACTS</span></span></span></td>
    </tr>
    <tr>
      <td class="Data"><table width="100%" border="0" align="center">
        <tr>
          <td width="32%"><span class="Data2"><%=(RSLandmarks.Fields.Item("ContactType1").Value)%></span></td>
          <td width="46%"><span class="Data2"><%=(RSLandmarks.Fields.Item("PrimaryContact").Value)%></span></td>
          <td width="22%"><span class="Data2"><%=(RSLandmarks.Fields.Item("PrimaryPhone").Value)%></span></td>
          </tr>
        <tr>
          <td><span class="Data2"><%=(RSLandmarks.Fields.Item("ContactType2").Value)%></span></td>
          <td><span class="Data2"><%=(RSLandmarks.Fields.Item("Contact2").Value)%></span></td>
          <td><span class="Data2"><%=(RSLandmarks.Fields.Item("Phone2").Value)%></span></td>
          </tr>
        <tr>
          <td><%=(RSLandContacts.Fields.Item("ContactType").Value)%></td>
          <td><%=(RSLandContacts.Fields.Item("ConName").Value)%></td>
          <td><%=(RSLandContacts.Fields.Item("Phone").Value)%></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td class="Data">&nbsp;</td>
    </tr>
  </table>
</form>
<p class="Fonts2">&nbsp;</p>
<p class="Fonts2">&nbsp;</p>
</body>
</html>
<%
RSLandmarks.Close()
Set RSLandmarks = Nothing
%>
<%
RSLandContacts.Close()
Set RSLandContacts = Nothing
%>


Old Pedant 03-15-2013 08:02 PM

Okay, try this replacement. (I truly *HATE* DreamWeaver code. I cleaned up a lot of it, but not all. But enough to make this somewhat more efficient, at least. The stuff in red is the important part. Other changes not as important, but they will make your code more efficient if you use them.)
Code:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/Landmarks.asp" -->
<%
' the code I had suggested:
parts = Split( Trim( Request("landname") ), "$$" )
id = CLNG(parts(0))
landmark = parts(1)

Set conn = Server.CreateObject ("ADODB.Connection")
conn.Open MM_Landmarks_STRING

SQL1 = "SELECT * FROM dbo.tblLandmark WHERE LandName = '" & Replace(landmark,"'","''") & "'"
Set RSLandmarks = conn.Execute(SQL1)

SQL2 = "SELECT * FROM dbo.tblLandmarkContacts WHERE FromID = " & id
Set RSLandContacts = conn.Execute(SQL2)

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body {
        background-color: #000;
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        color: #0FF;
}
.Fonts {
        font-size: 24px;
}
OtherFonts {
        color: #FF0;
}
.Data2 {
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        font-size: 10px;
        color: #FFF;
        text-align: left;
}
.Fonts2 {
        color: #FF0;
        font-size: 12px;
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        text-align: left;
}
.Fonts2Heading {
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        color: #FF0;
}
.Fonts table tr td .Fonts2Heading .Fonts2 .Fonts2Heading {
        font-weight: bold;
}
.Data {
        font-size: 12px;
        color: #FFF;
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        text-align: left;
}
.Fonts #form1 table {
        text-align: left;
        font-size: 10px;
}
</style>
</head>

<body class="Fonts">
<table width="100%" border="0">
  <tr>
    <td><div align="center">Landmark Info Display</div></td>
  </tr>
</table>
<p>&nbsp;</p>
<form id="form1" name="form1" method="get" action="">
<table width="100%" border="0" align="center">
    <tr>
      <td width="64%"><span class="Fonts2"><%=RSLandmarks("LandName")%></span></td>
    </tr>
    <tr>
      <td class="Data"><span class="Data2"><%=RSLandmarks("StNumber")%> <%=RSLandmarks("Dir")%> &nbsp; <%=RSLandmarks("Address")%></span></td>
    </tr>
    <tr>
      <td class="Data"><span class="Fonts"><span class="Fonts"><span class="Fonts2">CONTACTS</span></span></span></td>
    </tr>
    <tr>
      <td class="Data"><table width="100%" border="0" align="center">
        <tr>
          <td width="32%"><span class="Data2"><%=RSLandmarks("ContactType1")%></span></td>
          <td width="46%"><span class="Data2"><%=RSLandmarks("PrimaryContact")%></span></td>
          <td width="22%"><span class="Data2"><%=RSLandmarks("PrimaryPhone")%></span></td>
          </tr>
        <tr>
          <td><span class="Data2"><%=RSLandmarks("ContactType2")%></span></td>
          <td><span class="Data2"><%=RSLandmarks("Contact2")%></span></td>
          <td><span class="Data2"><%=RSLandmarks("Phone2")%></span></td>
          </tr>
        <tr>
          <td><%=RSLandContacts("ContactType")%></td>
          <td><%=RSLandContacts("ConName")%></td>
          <td><%=RSLandContacts("Phone")%></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td class="Data">&nbsp;</td>
    </tr>
  </table>
</form>
<p class="Fonts2">&nbsp;</p>
<p class="Fonts2">&nbsp;</p>
</body>
</html>
<%
RSLandmarks.Close()
RSLandContacts.Close()
conn.Close
%>


Old Pedant 03-15-2013 08:05 PM

If it's not obvious, all the other changes took the form of replacing this DrunkWalker crap:
Code:

<%=(RSLandmarks.Fields.Item("ContactType1").Value)%>
(and similar code) with just
Code:

<%=RSLandmarks("ContactType1")%>
The DoofusWhacker code works, but all it does is run slower than the more compact form.

stanleyc 03-15-2013 08:31 PM

Works like a charm!!! THANK YOU!!!

Chris

Old Pedant 03-15-2013 09:23 PM

You know, I'm going to guess that there is one more thing you should do.

Replace this code:
Code:

        <tr>
          <td><%=RSLandContacts("ContactType")%></td>
          <td><%=RSLandContacts("ConName")%></td>
          <td><%=RSLandContacts("Phone")%></td>
        </tr>

With this:
Code:

<%
Do Until RSLandContacts.EOF
%>
        <tr>
          <td><%=RSLandContacts("ContactType")%></td>
          <td><%=RSLandContacts("ConName")%></td>
          <td><%=RSLandContacts("Phone")%></td>
        </tr>
<%
    RSLandContacts.MoveNext
Loop
%>

I suspect that each landmark *could* have multiple contacts, and this code will then show all contacts.


All times are GMT +1. The time now is 06:05 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.