Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate form entry against ValueList variable

Status
Not open for further replies.

xsw1971

Programmer
Jun 21, 2001
153
US
Before a user submits a form, I would like to validate one of their entries against a ValueList variable that was created when the page was opened.

I want to prevent a user from entering a duplicate asset number and right now the form is submitted and the verification is done on the server. If the asset number exists they are sent back to the form, however all the form fields are empty and they have to start over.

The database has more than 5000 assets so the ValueList variable is quite large. I'm not sure how to get it into JavaScript or how to manipulate it once there. The ListFind function is perfect but since that's server side it won't work.

Any ideas?
 
you need do implement some sort of form handling. On my for action pages, all the entries are checked for validity, on errors, all the entries with errors are saved in a session variable as structure with the form field name and error message. All the form field values are send back also so the user does not have to re-enter everything. SO i get custome error messages per field, what fields had errors, and all the field values filled in.

to use javascript on page to check against a valuelist of 5000+ records, that means you would have to print in the html, the valuelist...a comma separted list of 5000+ id numbers printed in the html code every time the page is downloaded, that would not be a wise thing to do.

do server side validation, and send the user back to the form page with the already filled out form populated with the prvious entries. once you are familiar with a method that you like, it is really easy, and you'll wish you've always done it that way.


 
Thanks imstillatwork for the feedback. Just before you responded I figured out what I needed to do using JS! I just had to use regular expression matching to pull the value out of the "list". Even though the "list" has over 5000 "elements" in it, this executes instantly.

First I created my query of values to check against and I created a valuelist called lstAssets. I assigned the value of that that variable using #toScript()#. If you don't have MX7 you can assign it to a hidden form field.

Here's the script that gets called when all the other form validation occurs:
Code:
<script type="text/javascript">
  <cfoutput>
    var #toScript(lstAssets, "jsLstAssets")#;
  </cfoutput>

  function checkAssets() {
    var jsAssetValue = ","+document.forms[0].f_asset.value.toUpperCase()+",";

  if (jsLstAssets.match(jsAssetValue)) {
    alert("That asset number already exists.  Please enter a new one.");
    return false;
  } else {
    return true;
  }
}
The reason I put commas in front and behind my search string is to prevent partial searches within my valuelist variable. For example if the list contained ...,12345,1234567,... and my user input 123456 without the commas at the start/end it will match the 1234567 entry and tell me it's already used, when in fact it isn't. The values that are input into this field won't ever contain commas, but if they did I could just assign a different delimiter in the valuelist.
 
is the entire list of ids in the html source when viewed? I haven't use the toscript() function

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top