troubleshooting Question

ASP Array to Javascript Array / Form Validation

Avatar of cipiWeb
cipiWeb asked on
5 Comments2 Solutions347 ViewsLast Modified:
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.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros