View Full Version : Checking entered value against Database Value ... best solution???

02-01-2005, 06:34 PM
I am currently checking two database values on different pages in different ways using javascript. Which way is best?

Solution 1: I create a string of known values in JS as a variable (US zip codes). I then do a search on that string to see if the entered value is in the string. If the value is in the string, it's a good value and everything is OK. If it's not, the zipcode is invalid. The variable string is composed server side before presenting the page to the client browser using ColdFusion with a simple query of the database.

Question on Solution 1: This list is rather large as the string is a comma seperated list of all the US zipcodes ... 42,489 of them! That's 254,934 characters (42,489 "," seperators & 42,489 5 character "strings")!!! Is there a limit to the size of a javascript string variable?

Solution 2: Script on page 1 does some preliminary checking on the length and cofiguration of the string being entered. If this passes, it calls another function, which passes the string value to a ColdFusion page, which checks the database for the submitted value. If the value is found, the popup window closes and nothing happens because the value entered is valid (found in database). However, if the query returns 0 results, the popup window sends a call to a function on the parent window (the opener) and passes a result count of 0. The parent window function uses this value to determine if it will or will not throw an alert.

Obviously, solution 2 is more complicated and involved, but works just fine. However, I like the smoothness (no popup windows) of the first solution. My problem is not knowing the limitations of javascript with regards to variable string length. Although the new string for Solution two would be smaller, both database tables have the ability to be updated periodically.



02-02-2005, 03:51 PM
Well, I think I need to find a more graceful way of using the popup method. I did a little experiment and looked at the size of the page with the string variable in and without. 290KB with the test string and only 67.6KB without ... that is a huge difference. However, the page will only be used by 4-5 people as it's part of our intranet for a very specific need that only 4-5 people in the company use.