Link to home
Create AccountLog in
Avatar of cipiWeb

asked on

ASP Array to Javascript Array / Form Validation

How can I convert an ASP Array to javascript?
     - - or (based on the DETAILS) - -
What is the best validation approach to my problem?

     Q: Why?
     A: I want to validate a form without the user losing edit data if the validation fails (returns false)


I am setting up a page that allows the user to update a record. It is set up to key off of  two values, so setting a primary key for me will not work.

Value 1 is the type, Value 2 is the Item.

I want to set it up so that the name of the item has to be unique within the Type.
For Example:

Type1     VariableAAA
Type1     VariableBBB
Type1     VariableCCC
Type1     VariableABC

Type2     VariableAAA
Type2     VariableDDD
Type2     VariableEEE
Type2     VariableXYZ

The AAA value can still exist in a different Type. But I don't want it to duplicate within the type.

When creating a new entry, or updating an existing one, I want it to check to make sure that the ITEM doesn't already exist.

I realize a few issue come up for this. One being that it will find itself while checking all the ITEMs in a TYPE. Since in finding itself it would already exist, you would not be able to edit the entry your working on, So I figured I could check the submitted value against the original value, if the ITEM value has not changed, then there is no need to validate that field and then it will return true and allow the form to process and send it to the query script.

I want to perform the validation on the same page using javascript, so I was thinking that I would simply make a query to list all the ITEMs within a certain TYPE with the GetRows. If I could pass the data to Javascript, I could call it with the onsubmit event. IF the ITEM has changed, then run a loop through the array, if the ITEM exists, then alert the user and return false, ELSE return true, and the form will be sent to another script for database processing.

My initial question is this: How can I convert an ASP Array to javascript?

I was thinking about running a loop to Response.Write the Array in a <script> tag located in the <head> portion of the document, but I am concerned about whether or not this would be a smart move, much less secure because it would be printing out a list of field values that ccould be viewed with View Source, given this is something an admin has access to anyway, but it still concerns me.

Should I consider validating this another way? Passing the original and the edited values to the query script and validating server side?

Thank you.
Avatar of tctekkie
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of cipiWeb


I have a couple of questions on your comment.

2. How does Javascript use bandwidth if it takes place on the clients machine?
4. I am guessing you ment annoying???
Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of cipiWeb


I am more fluent in that language than I care to admit!

I have upon my server side approach on the following thread. If you have any ideas on how to solve the problem it would be much appreciated as the deadline is creeping closer!

Thank you for your input.