Avatar of cipiWeb
cipiWeb
 asked on

ASP Array to Javascript Array / Form Validation

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

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

DETAILS:

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?

ALL INPUT IS WELCOME!
Thank you.
ASP

Avatar of undefined
Last Comment
cipiWeb

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
tctekkie

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
cipiWeb

ASKER
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???
SOLUTION
tctekkie

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
cipiWeb

ASKER
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.
cipiWeb

ASKER
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck