how to pass an array of data with hidden fields or cookies?

F

Fred

Hi,

i know how to pass a value from Javascript to ASP with a hidden field into a
form and submitting it, or with cookies, but here i have to pass a lot of
data in an array.

There is a list of product the visitor can order by clicking one or more
checkboxes. I made a form containing input with type "checkbox" like:
<form>
<input type="checkbox" name=ck id=ck
<input type="checkbox" name=ck id=ck
....
<input type="checkbox" name=ck id=ck
</form>

I made a function which detect the checked products and which put those
productnumbers into an array, suppose prod. That's ok.
But now, how can i pass that array to another ASP-page, where those
productnumber must be put into the database? It's not realistic to make a
lot of hidden fields, certainly because the amount vary each time.

Thanks for any hints
Fred
 
B

Bob Barrows [MVP]

Fred said:
Hi,

i know how to pass a value from Javascript to ASP with a hidden field
into a form and submitting it, or with cookies, but here i have to
pass a lot of data in an array.

There is a list of product the visitor can order by clicking one or
more checkboxes. I made a form containing input with type "checkbox"
like: <form>
<input type="checkbox" name=ck id=ck
<input type="checkbox" name=ck id=ck
...
<input type="checkbox" name=ck id=ck
</form>

I made a function which detect the checked products and which put
those productnumbers into an array, suppose prod. That's ok.


Use join() to create a delimited string from the array, and write it into a
hidden textbox:
But now, how can i pass that array to another ASP-page, where those
productnumber must be put into the database? It's not realistic to
make a lot of hidden fields, certainly because the amount vary each
time.


documentGetElementById("txtHidden").value = prod.join(",")

Then, in the ASP to which the above form is posted, use Split() to create
your array:

<%
dim arChecks
arChecks=Split(Request.Form("txtHidden"),",")
%>

Actually, this task can be made simpler. Try out this small asp page which
posts to itself:

<%
Response.Write Request.Form("ck") & "<BR>"
%>
<HTML>
<BODY>
<form method="post">
<INPUT type="checkbox" id=ck1 name=ck value="1">
<INPUT type="checkbox" id=ck2 name=ck value="2">
<INPUT type="checkbox" id=ck3 name=ck value="3">
<INPUT type="checkbox" id=ck4 name=ck value="4">
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
</form>
</BODY>
</HTML>


By giving the same name to each of the checkboxes, you enabled the page that
processes the submission to treat them as a single unit. You can also do
this:

<%
dim key
for each key in Request.Form("ck")
Response.Write key & "<BR>"
next
%>



Bob Barrows
 
B

Bob Barrows [MVP]

Please don't multipost. I've already replied to this question over at
..asp.db (where it was somewhat offtopic, having nothing to do with
databases). Posting the question
here as well did not increase your chances of getting an answer (most of us
subscribe to both groups). On the contrary, if somebody had taken his time
to answer it here, only to find that it was already resolved in the other
group, that person may have been annoyed enough to ignore any future posts
from you, thereby decreasing your chances of getting help in the future.


There are times when you will not be sure which group is most appropriate
(again, this was not one of them), and you will want to post a question to
both groups. In that situation, you should use the cross-posting technique,
rather than posting the same message multiple times. To crosspost, put
a semicolon-delimited* list of the newsgroups to which you wish to post in
the To: header of your post and post it once. It, and any replies to it,
will appear in all the newsgroups in your list. So, if I reply in .asp.db,
my reply will also appear here in .asp.general.

Bob Barrows
 
B

Bob Barrows [MVP]

Oops. I just realized that you crossposted this message instead of
multiposting it. Please ignore my previous reply (which I have just
attempted to cancel). Instead, I would like to offer the thought that this
question has nothing to do with databases and therefore probably should not
have been crossposted to the .db group. However, this breach of netiquette
is not nearly as extreme as a multipost would have been.



Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top