Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

singel quote in drop down

Posted on 2001-08-12
19
Medium Priority
?
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +7
19 Comments
 
LVL 18

Expert Comment

by:nigelrivett
ID: 6378141
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
ID: 6378275
No luck. I tried both options :(
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6378381
Post your code so we will know what you actually wanted.

hongjun
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:russoffl
ID: 6378427
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
ID: 6378547
Rotigel,

Using SERVER.HTMLEncode():

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


Regards,
Wee Siong
0
 

Expert Comment

by:vishwanathl
ID: 6378550
Try this

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

And let me know if it helped
0
 
LVL 20

Expert Comment

by:Michel Sakr
ID: 6378587
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
ID: 6379501
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
ID: 6379508
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
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 200 total points
ID: 6379561
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:Michel Sakr
ID: 6379686
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
ID: 6379720
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
ID: 6380281
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
ID: 6380382
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
ID: 6381114
GreenGhost

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

Author Comment

by:Rotigel
ID: 6385982
Didn't work :(
0
 
LVL 1

Author Comment

by:Rotigel
ID: 6385984
That works! Thanks a million!!!!
0
 
LVL 20

Expert Comment

by:Michel Sakr
ID: 6395922
and what I said was different? DOH!
0
 
LVL 1

Author Comment

by:Rotigel
ID: 6404552
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

636 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