Code Comments
Programming Forum and web based access to our favorite programming groups.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[i]. 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
Post Follow-up to this messageFred wrote:
> 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[i]. 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
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Post Follow-up to this messagePlease 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 -- Microsoft MVP - ASP/ASP.NET Please reply to the newsgroup. This email account is my spam trap so I don't check it very often. If you must reply off-line, then remove the "NO SPAM"
Post Follow-up to this messageOops. 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 -- Microsoft MVP - ASP/ASP.NET Please reply to the newsgroup. This email account is my spam trap so I don't check it very often. If you must reply off-line, then remove the "NO SPAM"
Post Follow-up to this messageThanks "Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message news:u8GUKcduEHA.2300@TK2MSFTNGP09.phx.gbl... > 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 > -- > Microsoft MVP - ASP/ASP.NET > Please reply to the newsgroup. This email account is my spam trap so I > don't check it very often. If you must reply off-line, then remove the > "NO SPAM" > >
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.