473,323 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

How to handle an apostrophe in a text field

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 3584
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.