Connecting Tech Pros Worldwide Forums | Help | Site Map

Validate Text box value against database

Member
 
Join Date: Jun 2009
Posts: 37
#1: Jul 1 '09
Hi Team,

I have designed a dynamic form with number of elements, i am stuck with a requirement where i need your help.

The requirement is :
While a user fills out the form, one particular text box value (User ID) needs to validated against a database table to check whether the user ID exists in the database table called Table1. If the UserID does not exists then an error message should be displayed.
I am making use of ASP classic for form design , VBScript for database connectivity
and Java Script for form validation.

If someone could help me out in coding this requirement, that will be much appreciated.

Many thanks

GazMathias's Avatar
Expert
 
Join Date: Oct 2008
Location: Bristol, United Kingdom
Posts: 143
#2: Jul 2 '09

re: Validate Text box value against database


Hi

Quote:
The requirement is :
While a user fills out the form, one particular text box value (User ID) needs to validated against a database table to check whether the user ID exists in the database table called Table1. If the UserID does not exists then an error message should be displayed.
You would need to use AJAX to do what you want. I recommend jQuery as it makes this type of thing a breeze (and lots more besides).

Perhaps a better way is to only provide the user with the values they can use to begin with (via a prepopulated select box), that way they can not get it wrong.

If the UserID you talk about is related to the user actually using the system, you might seriously want to think about creating a login system instead as this poses all sorts of security and usability concerns.

Gaz
Member
 
Join Date: Jun 2009
Posts: 37
#3: Jul 2 '09

re: Validate Text box value against database


It is an application already built in ASP (front end), JavaScript(form validation and several other conditions), and VBscript for connectivity.I am not used to AJAX coding, never worked on it.. So Is there a way that i can accomplish this requrement using VBScript??

Can we write the database connection string inside a VBscript FUNCTION() ?? Does this work??
GazMathias's Avatar
Expert
 
Join Date: Oct 2008
Location: Bristol, United Kingdom
Posts: 143
#4: Jul 2 '09

re: Validate Text box value against database


Quote:
JavaScript(form validation and several other conditions), and VBscript for connectivity.I am not used to AJAX coding, never worked on it
Then what's the problem, AJAX simply is JavaScript!

You would use the onChange event to trigger the AJAX call to a VBScript page which would check your database for you and return something.

Like I said before, using a library like jQuery, this task is simpler than you might think.

Gaz.
Member
 
Join Date: Jun 2009
Posts: 37
#5: Jul 2 '09

re: Validate Text box value against database


Can you please send an example code per your note above..Because i am very new to this AJAX and haven't worked on it anytime...
GazMathias's Avatar
Expert
 
Join Date: Oct 2008
Location: Bristol, United Kingdom
Posts: 143
#6: Jul 3 '09

re: Validate Text box value against database


I may knock up something later if I get time.

Did you consider this approach? :

Quote:
Perhaps a better way is to only provide the user with the values they can use to begin with (via a prepopulated select box), that way they can not get it wrong.
Gaz
Member
 
Join Date: Jun 2009
Posts: 37
#7: Jul 7 '09

re: Validate Text box value against database


When the numbers are more than 1000 or more it is not possible to provide all the values in a drop down.. Rather we have to validate the value entered against the database. So i want someone to comeup with an idea as you did..
GazMathias's Avatar
Expert
 
Join Date: Oct 2008
Location: Bristol, United Kingdom
Posts: 143
#8: Jul 7 '09

re: Validate Text box value against database


You have really only two choices then:

1) Check the value once its been posted, though the form will be reset if you bounce the user back if it is wrong.

2) Use an AJAX technique to query the database as the form is filled.

If you don't understand what I mean by this it is very much like when you type in the Google search bar and it suggests values for you.

The only difference is that instead of displaying suggested values, you will simply not allow the form to submit and maybe unhide a div with a message in it.

Does that make sense?

Try searching for "AJAX search tutorial" or similar.

Gaz.
Member
 
Join Date: Jun 2009
Posts: 37
#9: Jul 7 '09

re: Validate Text box value against database


Makes sense.. I will try searching as you suggested. And if i give you the code can you edit it for me cos i am running short of time i need to complete my Academic project work by the end of this week.. I will start my search so that i can get something to fix this issue..Thanks

chandhu
Reply

Tags
<form>, <option>, <script>, <select>