How can I check for duplicates before submitting a form?

M

Mike

I have a form that has places for the
client to enter 20 different debts.

I cannot have any duplicate entries.

For example:

1 = Discover Card
2 = Discover Card
3 = Visa - Circuit City
4 = Visa - AT&T
5 = etc....

I want it to compare these fields and
tell the person, entering the data, that
there cannot be any duplicate names.
(#1 & #2 are duplicate)

Thanks,

Mikeal
 
J

Jim Buyens

I would do this with ASP or ASP.NET code on the server.

In ASP, I'd create a disconnected recordset, add a row for
each debt, create a view sorted on debt name, and then
scan the view looking for duplicates.

In ASP.NET the process is much the same, except thta I'd
use a DataTable rather than a disconnected recordset.

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
|| Microsoft FrontPage Version 2002 Inside Out
|| Web Database Development Step by Step .NET Edition
|| Troubleshooting Microsoft FrontPage 2002
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 
M

MD WebsUnlimited.com

If I was going to do this on the server side I would assume that the
database would have a third normal form and that this data would be placed
into a separate table. That table would contain a compound primary key that
is comprised of unique values using the credit card information.

Example

Customer Table
===========
First Name Credit Card Table
Last Name ============
Customer Number ---> Customer Number
Address1 Credit Card
Address 2
.....
...
...

The Fields Customer Number and Credit Card form a compound primary key value
that does not allow duplicates. If you attempt to add a record that is a
duplicate then an error would be raised.

Note this Scenario would require that transaction processing be done so that
the records entered prior to the error could be rolled back.

This would reduce the overall amount of processing required in a server side
solution.
--
Mike -- FrontPage MVP '97 - '02
http://www.websunlimited.com
Our latest products "At Your Command" and IncludeASP
http://www.websunlimited.com/order/Product/AYC/ayc.htm
http://www.websunlimited.com/order/product/includeASP/includeASP.htm
 
M

MD WebsUnlimited.com

Hi Mike,

Assuming that you wish to accomplish this on the clientside, and IMHO that
is where it should be accomplished, you'd use JavaScript to walk the fields
of the credit cards adding them to a array, then walk the fields again
comparing the hits agaist the array. If you get more than 1 hit you have a
duplicate.

I had a little time so view the source at:
http://www.fpplus.com/samples/CheckForUniqueness.htm


--
Mike -- FrontPage MVP '97 - '02
http://www.websunlimited.com
Our latest products "At Your Command" and IncludeASP
http://www.websunlimited.com/order/Product/AYC/ayc.htm
http://www.websunlimited.com/order/product/includeASP/includeASP.htm
 
J

Jim Buyens

MD WebsUnlimited.com said:
If I was going to do this on the server side I would assume that the
database would have a third normal form and that this data would be placed
into a separate table. That table would contain a compound primary key that
is comprised of unique values using the credit card information.

..

The Fields Customer Number and Credit Card form a compound primary key value
that does not allow duplicates. If you attempt to add a record that is a
duplicate then an error would be raised.

Tough one, because we're both making assumptions that weren't in the
original question.

I assumed the problem as a loan application, wherein the customer
would list all open debts. The form would have 10 or 20 rows of text
boxes, with each row containing boxes for one Credit Card Name, Credit
Card Number, Expiration Date, Balance, and so forth.

I also assumed the requirement of getting all the data right before
attempting any database updates. That's why I loaded the data into a
disconnected recordset rather than attempting to add it to a database.

If you want to assume the requirement as starting a transaction,
attempting to load the data into a real database table, watching for
exceptions, and then doing backouts, that's equally valid (although
more resource intensive).

A reasonable person could also assume adding the data into the
database even if it contains errors, but setting some sort of status
code to Error so that no further processing occurred.

As to performing this edit on the browser, yet, it could be done, but
it could also be circumvented. I never, never, never trust a
browser-side edit.

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
|| Microsoft FrontPage Version 2002 Inside Out
|| Web Database Development Step by Step .NET Edition
|| Troubleshooting Microsoft FrontPage 2002
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 
M

Mike

Thank You!
This is what I needed.

Mikeal

MD WebsUnlimited.com said:
Hi Mike,

Assuming that you wish to accomplish this on the clientside, and IMHO that
is where it should be accomplished, you'd use JavaScript to walk the fields
of the credit cards adding them to a array, then walk the fields again
comparing the hits agaist the array. If you get more than 1 hit you have a
duplicate.

I had a little time so view the source at:
http://www.fpplus.com/samples/CheckForUniqueness.htm


--
Mike -- FrontPage MVP '97 - '02
http://www.websunlimited.com
Our latest products "At Your Command" and IncludeASP
http://www.websunlimited.com/order/Product/AYC/ayc.htm
http://www.websunlimited.com/order/product/includeASP/includeASP.htm
-------------------------------------------------------------------------- --
 
M

Mike

One more thing....

My form has places for 20 fields and most of them will be left blank. It is
always giving me an duplicate warning because of the blank fields. Is there
any way to elininate null value fields?

Mikeal
 
L

Lisa Wollin \(Microsoft\)

You can also use javascript to validate form data before sending it to the
server. Check out http://javascript.internet.com/forms/val-cookie.html or
http://www.webreference.com/js/tips/000124.html. You can find many more
resources as well by doing a search for "form validation." Keep in mind,
however, that since JavaScript is done in the browser, users will need to
have JavaScript enabled. If you are uncertain whether your users will have
JavaScript enabled, validating on the server as Jim recommends is probably
best.

--
Lisa Wollin
Programmer Writer
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top