Hi,
You make a very good case for using an identity column. However, this code works like a charm. It seems that it does work using ASP to encode the URL but for some reason once you encode the text it doesn't add the comma delimiter on the post so I just added it to the javascript: strSel += sel[item].value + ",\n";
Never have I seen so many posts to such a simple problem. Tulin, you are a lucky man.
CREATE TABLE [Supplier] (
[SuppID] [int] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL ,
[SuppName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Supptext] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
<html>
<head>
<title>Select Test</title>
<script language="javascript">
function getSelected(opt) {
var selected = new Array();
var index = 0;
for (var intLoop=0; intLoop < opt.length; intLoop++) {
if (opt[intLoop].selected) {
index = selected.length;
selected[index] = new Object;
selected[index].value = opt[intLoop].value;
selected[index].index = intLoop;
}
}
return selected;
}
function outputSelected(opt) {
var sel = getSelected(opt);
var strSel = "";
for (var item in sel)
//alert (sel[item].value)
strSel += sel[item].value + ",\n";
// alert("Selected Items:\n" + strSel);
window.location='select.asp?Supplier=' + strSel;
}
</script>
</head>
<body leftmargin="0" topmargin="0">
<br><br>
<form Name="myform" method="post">
<select NAME="Supplier" SIZE=4 MULTIPLE >
<option value="<% Response.Write Server.URLencode("Red & Lease") %>">Red & Lease</option>
<option value="<% Response.Write Server.URLencode("Tech & Lease") %>">Tech & Lease</option>
<option value="<% Response.Write Server.URLencode("richie&Lease") %>">richie&Lease</option>
<option value="<% Response.Write Server.URLencode("bill&Lease") %>">bill&Lease</option>
</select>
<br>
<INPUT TYPE="BUTTON" NAME="open" VALUE="SUBMIT" ONCLICK="outputSelected(this.form.Supplier.options )">
<br>
<%
supplier = Trim(Request("Supplier"))
If Len(supplier) > 0 Then
thevalues = split(supplier, ",")
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open Application("conn")
For i = 0 to ubound(thevalues)
SQL = "Select * from Supplier where SuppName = '" & thevalues(i) & "';"
Set oRS = oConn.Execute(SQL)
If not oRS.EOF Then
Response.Write "<br><b>Supplier:</b> " & oRS("SuppName") & " - - - - " & oRS("Supptext") & "<br>"
End If
Next
oRS.Close
Set oRS = Nothing
oConn.Close
Set oConn = Nothing
End If
%>
</body>
</html>
|