...

View Full Version : Running a Query Against Form Field Validation



kraftomatic
09-27-2005, 03:00 PM
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!

nikkiH
09-27-2005, 03:04 PM
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)?

kraftomatic
09-27-2005, 03:06 PM
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?

nikkiH
09-27-2005, 09:01 PM
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?

kraftomatic
09-28-2005, 01:28 AM
I think I've actually got it figured out .. thanks for the help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum