Validate Text box value against database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chandhseke
    New Member
    • Jun 2009
    • 92

    Validate Text box value against database

    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; Jul 1 '09, 05:57 PM. Reason: moved to the Q&A section
  • GazMathias
    Recognized Expert New Member
    • Oct 2008
    • 228

    #2
    Hi

    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

    Comment

    • chandhseke
      New Member
      • Jun 2009
      • 92

      #3
      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??

      Comment

      • GazMathias
        Recognized Expert New Member
        • Oct 2008
        • 228

        #4
        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.

        Comment

        • chandhseke
          New Member
          • Jun 2009
          • 92

          #5
          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...

          Comment

          • GazMathias
            Recognized Expert New Member
            • Oct 2008
            • 228

            #6
            I may knock up something later if I get time.

            Did you consider this approach? :

            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

            Comment

            • chandhseke
              New Member
              • Jun 2009
              • 92

              #7
              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..

              Comment

              • GazMathias
                Recognized Expert New Member
                • Oct 2008
                • 228

                #8
                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.

                Comment

                • chandhseke
                  New Member
                  • Jun 2009
                  • 92

                  #9
                  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

                  Comment

                  Working...