Connecting Tech Pros Worldwide Help | Site Map

Validate Text box value against database

  #1  
Old July 1st, 2009, 04:41 PM
Member
 
Join Date: Jun 2009
Posts: 34
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

Last edited by jhardman; July 1st, 2009 at 06:57 PM. Reason: moved to the Q&A section
  #2  
Old July 2nd, 2009, 10:14 AM
GazMathias's Avatar
Expert
 
Join Date: Oct 2008
Location: Bristol, United Kingdom
Posts: 138

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
  #3  
Old July 2nd, 2009, 04:07 PM
Member
 
Join Date: Jun 2009
Posts: 34

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??
  #4  
Old July 2nd, 2009, 04:39 PM
GazMathias's Avatar
Expert
 
Join Date: Oct 2008
Location: Bristol, United Kingdom
Posts: 138

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.
  #5  
Old July 2nd, 2009, 05:07 PM
Member
 
Join Date: Jun 2009
Posts: 34

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...
  #6  
Old July 3rd, 2009, 11:01 AM
GazMathias's Avatar
Expert
 
Join Date: Oct 2008
Location: Bristol, United Kingdom
Posts: 138

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
  #7  
Old July 7th, 2009, 02:35 PM
Member
 
Join Date: Jun 2009
Posts: 34

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..
  #8  
Old July 7th, 2009, 04:09 PM
GazMathias's Avatar
Expert
 
Join Date: Oct 2008
Location: Bristol, United Kingdom
Posts: 138

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.
  #9  
Old July 7th, 2009, 04:35 PM
Member
 
Join Date: Jun 2009
Posts: 34

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>


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validate data during entry in table fields against database in ASP classic chandhseke answers 8 August 6th, 2009 04:48 PM
Onchange Event in Dropdown chandhseke answers 41 July 1st, 2009 04:21 PM
How to avoid script database hacking? RA answers 12 November 18th, 2005 04:33 PM
Ignoring spaces in combobox text Thelma Lubkin answers 14 November 13th, 2005 11:22 AM