Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2003
    Posts
    601
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Running a Query Against Form Field Validation

    Hey Guys,

    I'm trying to do this "compare" against a user's input to a particular form field value and wanted to see what would be the best way to do this.

    I have a form. In that form there is a field called id_number. When the user enters a number in the field (it will be a 1-3 digit number), I want an onBlur statement to compare it to an array of existing numbers to make sure the user isn't picking one that's already taken.

    I'm using a database/ASP page, so I would have a query looking something like:

    SELECT id_number FROM tblName;

    So I would need to somehow loop through and grab all the existing id's from the db, probably store it in a JS array, then compare it to the form field value and give an error if the numbers match.

    Any ideas on how to do this?

    Thanks Much!

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    That could get pretty unwieldy when there are a lot of IDs in the table.
    Have you considered dynamic validation using AJAX (or postback in .NET)?

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Regular Coder
    Join Date
    Jul 2003
    Posts
    601
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by nikkiH
    That could get pretty unwieldy when there are a lot of IDs in the table.
    Have you considered dynamic validation using AJAX (or postback in .NET)?
    Max there would be say 100 id's. Still too much?

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Well, it would have to write that array and do a search using the user's PC.
    So, for intranet with good computers, no problem.
    For dial-up users, I'd do a quick file size test before deciding for sure to go this route (probably fine, though).
    For users with crappy slow computers, they will notice a definite lag when the search is done.

    So, probably be just fine.
    I don't think javascript has an array.contains type method, so you'd have to just write out your query as an array, then set up the onBlur handler to loop through it and check for a match.
    Is that the code you aren't sure how to write?

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    Regular Coder
    Join Date
    Jul 2003
    Posts
    601
    Thanks
    17
    Thanked 0 Times in 0 Posts
    I think I've actually got it figured out .. thanks for the help.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •