 |
| Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

September 29th, 2005, 10:05 AM
|
|
Authorized User
|
|
Join Date: Aug 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Here is the problem:
There is no problem with the following query:
"SELECT Count(PONUMBER) AS OpenPos FROM [qry PO_data calculated fields final] WHERE SUPPLIER IN (" &MSupp& ")"
My problem is that I can't pass value(s) with special characters from JavaScript function to asp page using <%SSupp= Request("Supp")%>.
Let me give a example:<option value="<%Tech&Lease%>"><%Tech&Lease%></option>
When I try to pass value from javascript to asp page using
<%SSupp= Request("Supp")%>
I get only SSupp=Tech
I can't get & symbol.
My question is that how can i pass value(s) with special characters from javascript to asp page.
Thanks,
|
|

September 29th, 2005, 10:26 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
When you right the value to the asp page use <% Response.Write Server.URLencode(var) %>. The ampersand is cutting the string.
|
|

September 29th, 2005, 10:42 AM
|
|
Authorized User
|
|
Join Date: Aug 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Nope, it doesn't work...
|
|

September 29th, 2005, 01:54 PM
|
|
Authorized User
|
|
Join Date: Aug 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Here is the my problem:
<select NAME="Supplier">
<option value="Tech&Lease">Tech&Lease</option>
</select>
<%SSupp= QueryString("Supplier")%>
I can only pull Tech part. How can I handle the "&" character using QueryString.
Thanks
|
|

September 30th, 2005, 12:27 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hiii tulincim!!
Here is the solution
****test.html******
<FORM NAME=MYFORM ACTION="TEST1.ASP">
<select NAME="Supplier">
<option value="Tech&Lease">Tech&Lease</option>
</select>
<INPUT TYPE=SUBMIT NAME=A VALUE=SUB>
</FORM>
**********TEST1.ASP********
<%
myvalue=request.querystring("Supplier")
response.write(myvalue)
%>
Which gives the result "Tech&Lease" in output/value
Hope this will help you :)
try this link
http://n.1asphost.com/vinodvinod/test.html
Cheers :)
vinod
|
|

September 30th, 2005, 03:09 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi tulincim,
Vinod's suggestion of submittng a form rather than navigating with javascript is a nice solution - let the browser take care of the encoding.
If you really want to do it with javascript, you can use encodeURIComponent() or encodeURI() methods.
Cheers,
Chris
|
|

October 3rd, 2005, 11:26 AM
|
|
Authorized User
|
|
Join Date: Aug 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
When I used "encodeURIComponent" or "encodeURI()", it gives the following error:
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'encodeURIComponent'
It doesn't work...
Thanks,
|
|

October 4th, 2005, 02:35 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Those methods are javascript, you can use them client-side when building a querystring.
Cheers,
Chris
|
|

October 4th, 2005, 11:43 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
Hi All,
Tulin presents a very good case for using "IDs" to retrieve data. In my experience you're just asking for trouble retrieving data through varchar values. If the database IDs were written to the form there wouldn't have been any problem with the original code. Only integers would have been passed and there wouldn't have been all this trouble with URL encoding.
However, the following code does work. You can have ASP handle the URLencoding. There is a comma added to the javascript function, strSel += sel[item].value + ",\n"; to insure that the SPLIT function on post would find the end of each entry.
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
SuppName SuppText
Red & Lease This is Red & Lease.
Tech & Lease Of course, you already know this is Tech & Lease.
richie&Lease And, yeah, this is richie&Lease.
bill&Lease You can tell, bill&Lease.
<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>
|
|

October 5th, 2005, 01:52 PM
|
|
Registered User
|
|
Join Date: Oct 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I haven't been using Java or html select options so the code may not be exactly correct but isn't is possible to use a different option text and option value in an html select element?
to use your example:
<select name="Supplier">
<option value="TechLease">Tech&Lease</option>
</select>
basically show the '&' to the user when he makes the selection but leave it out of the query string. your asp.net program can add it in later.
If you need to, you can use a substitute character instead of leaving it out and then have your asp.net code replace it. This way you can get the option values from a database without knowing all the possible values at design time.
Retrieving an item from the database to create the java code would simply be the reverse. Programmatically substitute the '&' with the substitute character when creating the option tag's value item.
This should solve your problem.
|
|
 |