Solved

singel quote in drop down

Posted on 2001-08-12
19
250 Views
Last Modified: 2008-03-17
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!
0
Comment
Question by:Rotigel
  • 5
  • 3
  • 2
  • +7
19 Comments
 
LVL 18

Expert Comment

by:nigelrivett
Comment Utility
Have you tried various options to see?

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

0
 
LVL 1

Author Comment

by:Rotigel
Comment Utility
No luck. I tried both options :(
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
Post your code so we will know what you actually wanted.

hongjun
0
 
LVL 1

Expert Comment

by:russoffl
Comment Utility
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.
0
 
LVL 7

Expert Comment

by:weesiong
Comment Utility
Rotigel,

Using SERVER.HTMLEncode():

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


Regards,
Wee Siong
0
 

Expert Comment

by:vishwanathl
Comment Utility
Try this

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

And let me know if it helped
0
 
LVL 20

Expert Comment

by:Silvers5
Comment Utility
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,"   '   ","   '   '   ")

0
 
LVL 1

Author Comment

by:Rotigel
Comment Utility
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!
0
 

Expert Comment

by:reddygh
Comment Utility
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
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 29

Accepted Solution

by:
Göran Andersson earned 50 total points
Comment Utility
Apostrophes (') is no problem for HTML. You only have to handle them in the SQL call.

Use this:
strSQL = "SELECT * from Online_For_Agency_Reps Where Agency = '" & Replace(Agency,"'","''") & "'"
0
 
LVL 20

Expert Comment

by:Silvers5
Comment Utility
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
0
 

Expert Comment

by:TDK031400
Comment Utility
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
0
 
LVL 29

Expert Comment

by:Göran Andersson
Comment Utility
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.
0
 
LVL 1

Expert Comment

by:russoffl
Comment Utility
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.
0
 

Expert Comment

by:TDK031400
Comment Utility
GreenGhost

Ah, okay - thanks for the tip.
0
 
LVL 1

Author Comment

by:Rotigel
Comment Utility
Didn't work :(
0
 
LVL 1

Author Comment

by:Rotigel
Comment Utility
That works! Thanks a million!!!!
0
 
LVL 20

Expert Comment

by:Silvers5
Comment Utility
and what I said was different? DOH!
0
 
LVL 1

Author Comment

by:Rotigel
Comment Utility
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 -
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now