473,473 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to handle an apostrophe in a text field

1 New Member
Hello,

I am brand new to .ASP and am being asked to debug a problem with handling apostrophes. I'm aware of the Replace function, but I'm not sure where in the code I should insert it.

I've attached a zip file with the 2 relevant .asp pages in it, and to replicate the problem, take the following steps:

Go to http://www.larter.com/v2/collections.asp?c=sig&i=1&s=34100219BW--00

Click on "Inquire"
You will be brought to the /locator.asp page and asked to fill in information. Only the Zip, Distance, and Email are required.

Use the Zip Code 08530 and select 15 miles for the distance.

The first entry should be Saunder's in Flemington, NJ.

The locator.asp page populates store information into the sidebar next to the map, and the Send Inquiry button calls the sendinquiryemail.asp page. The problem is that a store name with an apostrophe will give the following error when you click the button:


CDO.Message.1 error '8004020d'

At least one of the From or Sender fields is required, and neither was found.

/v2/sendinquiryemail.asp, line 121



When I use the Inspect Element function in Chrome, it shows the button's code with the data already populated, and the S after the apostrophe is broken off from the name. I am aware of the Replace("Field", "'", "''") code, but as I am very new to .asp I can't tell exactly where the store name is called from the database and where I should insert this code. Can anyone help me with this? Thanks in advance for any advice!

Doug Coyne
Attached Files
File Type: zip Bytes.zip (15.1 KB, 59 views)
Sep 23 '14 #1
1 3598
groverdghp
3 New Member
Hi dccoyne67,

I just had to figure this out myself, and with Company names, so I am happy to share how I managed it.
I did get a little lost in your code so I decided to just tell you how I do it and you can apply it to your specific situation.

Disclaimer: as I have a BBA in Information Management Systems from WAY long ago, but am self-taught for ASP, this may not be the BEST way, but it worked for me. If anyone else has any better thoughts, please improve on my suggestions. Also, I'm thinking that some of the Replace functions in my code may be overkill, but after much trial and error, this is how I finally removed all the errors and surprises, so I decided to run with it. One of these days, I'll go back and see if I can "clean" it up a bit. But I'm in no rush.

In my application, about half of my pages Post back to themselves, and I access the data via request.form, and half are loaded via a hyperlink, so I access the data from request.querystring. I discovered I needed to handle these two a little differently when loading the page and the variables for access and use. I'll address both for you. Also, I use the HTML code for apostrophe in my replace.

First, to address hyperlinking and request.querystrings

Before you build your querystring to send out, any field that has a potential apostrophe in it (street names can, too, etc.), should have the Replace function run on it. You can either

1. Perform this task as the querystring is being constructed, or
2. Assign the company name to a variable first, run Replace as part of the assignment, and then use the variable in the querystring.

I do both depending on my need.

Since I pass Company IDs and Company Names a lot, I set up a variable called linkQryStrg at the beginning of those page to maximize integrity. To set that variable, I use this code:

Expand|Select|Wrap|Line Numbers
  1. linkQryStrg="&qCmpID="& vCmpID&"&qCompany="&replace(vCompany,"'","'")
where the variable names with "q" are part of the querystring, and the variable names with the "v" are ASP variables being passed in.

Then, to create the hyperlink, it just looks like:

Expand|Select|Wrap|Line Numbers
  1. ...<a href='frmToGoTo.asp?qAction=Add&qID="&vID&linkQryStrg tabindex=29 onclick='return chkDirty(this)'>ADD NEW ITEM</a>...
Occasionally, I only need to send the company name and in only one place on a particular page, so I don't bother with the variable assignment. I just say:

Expand|Select|Wrap|Line Numbers
  1. ...<a href='frmToGoTo.asp?qAction=Add&qID="&vID&replace(vCompany,"'","'")&" tabindex=29 onclick='return chkDirty(this)'>ADD NEW ITEM</a>...
That covers creating the querystring for sending. When it gets to the destination page, use the Replace function as well when assigning the querystring value to its variable. One of my first variable assignments is always vCompany. The code is:

Expand|Select|Wrap|Line Numbers
  1. vCompany=replace(request.querystring("qCompany"),"'","'")
Additionally - anywhere on the page I refer to, display, or store the variable, I also use the Replace function. (This is because I also load these particular pages as a Post and you will see later that the Replace function is not run when assigning the variable then.)

For example:
1. When stored in a Hidden text field (so it can be accessed during a Post):

Expand|Select|Wrap|Line Numbers
  1. response.write("<td><input type=hidden name=txtCompName value='"&replace(vCompany,"'","'")&"'></td>"&chr(13))
OR
2. When just being displayed on the page:
Expand|Select|Wrap|Line Numbers
  1. response.write("<td colspan=3 class=dealer>"&replace(vCompany,"'","'")&"</td>"&chr(13))
The only time I do not run the Replace function on the Company value is when I am assigning variables from request.form values. In that case, the code looks like:
Expand|Select|Wrap|Line Numbers
  1. vCompany=request.form("txtCompName")
and the linkQryStrg is just:
Expand|Select|Wrap|Line Numbers
  1. linkQryStrg="&qCmpID="&vCmpID&"&qCompany="&vCompany
But everywhere else on the page, vCompany still has the Replace function run on it as shown above.

Again, adapt this to your needs. If it is a little confusing, please let me know your questions and I will clarify. Good Luck!
Oct 7 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Lakshmi Narayanan.r | last post by:
Hi..experts, I have a DSN connection for MySql with Asp. Used Text field to store the data. While displaying the data its gives the error,if field is empty. But works well if not empty. So pls...
1
by: Mike | last post by:
In my database there is a text field type that is used to enter street address. This address could be a few lines long, each line with a carriage return at the end. Is there a way to search for...
7
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to...
2
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic...
3
by: Santosh | last post by:
Hi, I have a requirement in which, I need to capture a loan amount and the amount of down payment for that loan. According to the requirement, the user is going to enter enter the loan amount and...
3
by: Roy Adams | last post by:
Hi I'm reposting this question because for some reason can't post follow up question to this thread. What I'm trying to do is put the value and text from a a select in to a text field and to a...
11
by: Woody Splawn | last post by:
Are there any problems with saving values to a database from a text field that has an apostrophy in it? I am using SQL Server 2000. My notes are not clear on this, but I seem to remember that if...
4
by: justin tyme | last post by:
Hello Experts! I would like to combine (which may not be the correct technical term) two text fields from the same table in a query. Specifically, text field A and text field B are both lists of...
1
by: Sheau Wei | last post by:
i want to make a search engine for may database. i want to make the radio option at the search engine, but how to handle the search at the radio and the text field
1
DebadattaMishra
by: DebadattaMishra | last post by:
Introduction In case of rich applications, you must have observed that a text field behaves like a dynamic combo box. When the user enters some characters in the text field, a popup will come up...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.