Validation on dynamic hidden fields

Results 1 to 3 of 3

Thread: Validation on dynamic hidden fields

  1. #1
    William Guest

    Default Validation on dynamic hidden fields

    I have a question that I think I have half a solution for. So, here goes.<BR><BR>We are using ASP as our server side scripting language, doing our database connectivity and such. We are using JavaScript to do form validation, but I don&#039t know much aboug JavaScript as a language.<BR><BR>My question is in regard to this situation:<BR><BR>We have a form where an &#039administrator&#039 will complete user registration form. We are using JavaScript to validate the form and pop up alert windows if anything is wrong. Most of the validation is staight forward stuff.<BR><BR>The area in which I am running into trouble is when I need to check to see if a Name and UserName entered into the form already exist in the database where the information is kept. I understand that JavaScript does not allow you to connect with a database (client side), so I can&#039t connect to the database and check a recordset as I might do with ASP. So, what I did is when I create the form, I hit the database (with ASP) and create a recordset. I then loop through each record in the record set and write hidden fields in the form that contain the Customer and UserName. So I have this:<BR><BR>Do While Not rsAdmin.EOF<BR>Response.Write "&#060;input type=hidden name=Customer" & iCounter & " value=" & rsAdmin("CustomerName") & iCounter & "&#062;"<BR>Response.Write "&#060;input type=hidden name=UserName" & iCounter & " value=" & rsAdmin("UserName") & iCounter & "&#062;"<BR>iCounter = iCounter + 1<BR>rsAdmin.MoveNext<BR>Loop<BR><BR>So, when the form is constructed, there are two hidden fields for each record in the database:<BR><BR>Customer1 and UserName1<BR>Customer2 and UserName2<BR>etc.<BR><BR>So, what I want to do, then, in my JavaScript validation, is Loop through each instance of Customer# and UserName#, and check to see if field Customer and UserName don&#039t already have an entry in the database. But I am not really sure how to go forward, on the JavaScript side anyways. I guess the big thing is I don&#039t know how to loop from 1 to a dynamic number.<BR><BR>Additionally, I have a question about performance. This should be pretty quick when I only have a few records, but what about if the database gets to 100? And, I guess that leads me to the question: Is there a better solution?<BR><BR>Thanks!<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Validation on dynamic hidden fields

    Hi, my name is William (although I go by Will), but I am of no relation to you.<BR><BR>I can, however, help you here -- or so I think. You see, the idea you have is interesting, but it isn&#039t fraud-proof. All someone would have to do is make his own HTML document with a form that submits a username and password (without checking existing ones) to the target document. That would bypass any form validation you have. I would suggest doing the validation on the server&#039s side. I can help you with that if you need any.<BR><BR>But, just for your information. I personally would prefer to put the information into an array in JavaScript instead of putting it into hidden input fields. Looping through arrays can be done like this:<BR><BR>var arr1 = new Array("the first or 0 item", "the second one", "the third one", "etc.");<BR>for (var i = 0; i &#060; arr1.length; i++){<BR> if (username == arr1[i]){<BR> // Do something<BR> }<BR>}<BR><BR>Now you can figure out how to write an array like that using VBScript, can&#039t you?

  3. #3
    William Guest

    Default RE: Validation on dynamic hidden fields

    Will;<BR><BR>I actually have this portion of the form being validated server-side with ASP (hopefully it is as it should be!). I check the value of the field Customer and, if that customer name already exists in the database, I put up an error message and make them use the &#039Back&#039 button on the browser to fix the problem. I just was hoping to do something On Submit so I could pop up a message before leaving the form.<BR><BR>As for your suggestion, you are saying I build an array in VBScript based on the Recordset, and then pass that array to the JavaScript validation and then loop through the array using the code you provide? I think I can do that, provided I know how to get that VBScript array and pull it into the JavaScript validation.

Posting Permissions

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