Link to home
Start Free TrialLog in
Avatar of Rotigel
Rotigel

asked on

singel quote in drop down

I'm building a search page that checks an Access database and displays all of tha matching results. The problem is I have about 6 choices in the drop-down list that have a single quote in them. Something like:

Dave's first choice

Since I can specify the value for this choice in the drop down list I think this may be the solution to my problem. The problem is I'm not sure if I should wrap the whole thing is double quotes or single quotes, or just the single quote in double quotes or what... What value should I specify for the option of, Dave's first choice" to work?

Thanks!
Avatar of nigelrivett
nigelrivett

Have you tried various options to see?

"Dave's first choice" should work as a string
so should
'Dave''s first choice'

Avatar of Rotigel

ASKER

No luck. I tried both options :(
Post your code so we will know what you actually wanted.

hongjun
THe single quote shouldn't be a problem.

<option value='" & RS("whatever") & "'">" & RS("whatever") & "</option>"

Use a single followed by a double for the value.

Hope that helps.
Rotigel,

Using SERVER.HTMLEncode():

<option value="<%=Server.HTMLEncode(RS("whatever"))%>"><%=RS("whatever")%></option>


Regards,
Wee Siong
Try this

Response.Write "<option value=""" & RS("whatever") & """>" & RS("whatever") & "</option>"

And let me know if it helped
Avatar of Michel Sakr
No need to double the things while displaying.. in your action page where you post data to simply set a replaces before querying the database like:

TheDropValue = Replace(TheDropValue,"'","''")


I added blanks so you can distinguish the above line:

TheDropValue = Replace(TheDropValue,"   '   ","   '   '   ")

Avatar of Rotigel

ASKER

Hummmmmm, I'm not having much luck here. Here is the drop down from the first page:

<form method="POST" action="Results.asp">
  <p align="left"><font face="Tahoma" size="2"><b>Select your agency from the list
  below.</b></font></p>
  <p align="left"><font face="Tahoma" size="2"><select size="1" name="agency">
    <option value="Aging">Aging</option>
    <option>Banking</option>
    <option>Bon-Ton</option>
    <option>City of Harrisburg</option>
    <option>Civil Service Commision</option>
    <option>Community &amp; Economic Development</option>
    <option>Conservation &amp; Natural Resources</option>
    <option>Corrections</option>
    <option>County of Dauphin</option>
    <option>Dauphin County HHS</option>
    <option>Education</option>
    <option>Environmental Protection</option>
    <option>Executive Offices</option>
    <option>Fish &amp; Boat Commission</option>
    <option>Game Commission</option>
    <option>General Services</option>
    <option>Health</option>
    <option>Health Care Cost Containment Council</option>
    <option>Highmark Inc.</option>
    <option>Historical &amp; Museum Commission</option>
    <option>Human Relations Commission</option>
    <option>ImaginePA</option>
    <option>Insurance</option>
    <option>Labor &amp; Industry</option>
    <option>Liquor Control Board</option>
    <option>Military &amp; Veterans' Affairs</option>
    <option>Office of Administration</option>
    <option>PA Emergency Management Agency</option>
    <option>PA Higher Education Assistance Agency</option>
    <option>PA Municipal Retirement System</option>
    <option>PA School Boards Association</option>
    <option>Probation &amp; Parole</option>
    <option>Public School Employes' Retirement Sys</option>
    <option>Public Utility Commission</option>
    <option>Public Welfare</option>
    <option>Public Welfare - Allegheny CAO</option>
    <option>Public Welfare - Bertolino</option>
    <option>Public Welfare - H&amp;W</option>
    <option>Public Welfare - Hsbg State Hospital</option>
    <option>Public Welfare - Loysville Complex</option>
    <option>Public Welfare - Torrance State Hospital</option>
    <option>Revenue</option>
    <option>Securities Commission</option>
    <option>Sproule &amp; Associates</option>
    <option>State</option>
    <option>State Civil Service Commission</option>
    <option value="State Employee's Retirement System">State Employee's
    Retirement System</option>
    <option>State Police</option>
    <option>State System of Higher Education</option>
    <option>The Curtis Group</option>
    <option>Transportation</option>
    <option>Turnpike Commission</option>
    <option>Washington Group International, Inc.</option>
  </select></font></p>
  <p align="left"><font face="Tahoma" size="2"><input type="submit" value="Submit" name="B1">&nbsp;&nbsp;
  <input type="reset" value="Reset" name="B2"></font></p>
</form>


+++++++++++end of drop-down+++++++++++++

And here is the results page:

<%@ Language=VBScript %>
<% Option Explicit %>
<% Response.Buffer = True %>

<!--#include file="adovbs.inc"-->
<!--#include file="DatabaseConnect.asp"-->

<%

 dim Agency
 Agency = request.form("agency")
 
 Dim strSQL
 strSQL = "SELECT * from Online_For_Agency_Reps Where Agency = '" & Agency & "'"

 
 Dim objRS
 Set objRS = Server.CreateObject("ADODB.Recordset")
 objRS.Open strSQL, objConn

 If objRS.eof Then    
 
 Response.Write "<center>There are no members in that Agency.  Click the back button and try again.<br><br></center>"    
         
 Else
         
%>
         
<html>

<head>
<title>Agency Membership Results</title>
</head>

<body>
<center><b><font size="5" color="#093A7F" face="Tahoma"> Members in
</font></b><br>&nbsp;<%="<b><font size=5 color=#093A7F face=Tahoma>" & Agency & "</b></font>"%></center>
<font face="Tahoma">
<br>
 <div align="center">
  <center>
 <TABLE bordercolor="#093A7F" border=1 width="100%">
       <TR>
          <TD align=center><B>Agency</B></TD>
          <TD align="center"><B>First</B></TD>
          <TD align="center"><B>MI</B></TD>
          <TD align="center"><B>Last</B></TD>
          <TD align="center"><B>Exp</B></TD>
          <TD align="center"><B>Email</B></TD>
       </TR>
 <%
    Do While Not objRS.EOF
        Response.Write "<TR><TD>" & objRS("agency") & "</TD>"
        Response.Write "<TD>" & objRS("FName") & "</TD>"
        Response.Write "<TD>" & objRS("MI") & "</TD>"
        Response.Write "<TD>" & objRS("LName") & "</TD>"
        Response.Write "<TD>" & objRS("Exp") & "</TD>"
        Response.Write "<TD>" & objRS("WorkEmail") & "</TD>"
            objRS.MoveNext
     
    Loop

    'Clean up our ADO objects
    objRS.Close
    Set objRS = Nothing

    objConn.Close
    Set objConn = Nothing

     
%>
 </table>
  </center>
</div>

<hr>



</font>



<p><font face="Tahoma"><b><a href="Default.asp">Search Again</a> | <a href="../../">HOME
Home Page</a></b>
</p>
</font>
</body>
<%
End If
%>



Thanks!
Hi
     
Replace single quote with some identifier (like "zzz") and later in next page replace that
Identifier by single Quote. This is one of the work arounds you can try.

for example,
.Write "<option value='" & replace(RsSub("myvalue"),"'","zzz") & "'>"     & RsSub("myvalue") & "</option>"    

In the second page,

Dim MyOptionvalue    
MyOptionvalue=trim(Request.QueryString("selvalue")) 'selvalue is your list box

if instr(MyOptionvalue,"zzz")>0 then MyOptionvalue=replace(MyOptionvalue,"zzz","'")    

I have tried the same example and it is working fine.

Best of luck
ASKER CERTIFIED SOLUTION
Avatar of Göran Andersson
Göran Andersson
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
huh didn't you read my post.. nothing should be changed while displaying.. only after you post and fetch the listbox info that will populate the sql query
Rotigel

Replace your quotes in the select line with chr(34)like this:-

strSQL = "SELECT * from Online_For_Agency_Reps Where Agency = " & chr(34) & Agency & chr(34)

TDK
Sorry, Silvers5, I kind of lost your perfectly good solution in the overflow of misleading suggestions. Points to Silvers5, if you find this solution sufficient, Rotigel.

TDK, we usually DON'T post a suggestion as a proposed answer, as that moves the question to the locked list.
If you have a lot of records in your database, and in your "Agency" field you are saving these long names - for each record, you probably will end up wasting a lot of space.

Personally I would switch to  three or four digit code for each dept and assign that as the value in the drop-down ie 'corr' for corrections, and 'sshe' for State System of Higher Education.  Then you wouldn't have this problem anyway.  Or you may want to move over to a relational database model if your data has to be meaningful.

Jsut a thought.
GreenGhost

Ah, okay - thanks for the tip.
Avatar of Rotigel

ASKER

Didn't work :(
Avatar of Rotigel

ASKER

That works! Thanks a million!!!!
and what I said was different? DOH!
Avatar of Rotigel

ASKER

Silvers5:
  I tried your answer and it did not work. I then tried the answer that I accepted and it did work. I justy tried yours again and it worked - so it must have been some problem on my part. Since you were first I'm going to give you 50 points. Sorry about this, it was my fault.

Thanks -