Using Arrays from Javascript

Using Arrays from Javascript

am 20.12.2007 21:37:53 von NoChat

Hi all --

I am new to arrays and could use some help. Here is my situation: I
have a very basic order form that I am allowing users to fill out.
They can enter multiple products onto this form, so I have created a
simple Javascript function that allows the user to dynamically add
another row of text boxes for each item he or she would like to
order. I am submitting the form to another ASP page which I hope can
read the information from the form and send an email notification to
somebody else.

I have already built the emailing portion of this ASP script, but I've
been unable to read in the various form items. I'm guessing there is
something incompatible with either my Javascript or ASP. I have
included the important code snippets below and could use some
assistance.

Thanks in advance!
--Ty

JAVASCRIPT & HTML CODE THAT CREATES DYNAMIC FORM OBJECTS
________________________________________________________


action="aspmail.asp">
id="order">


















 
id="Submit" value="Submit" />


________________________________________________________
ASP CODE I'M USING TO TRY AND READ IN THIS INFORMATION
________________________________________________________

Dim pub, qty, comments

'order information
pub = Array(Request.Form("pub"))
qty = Array(Request.Form("qty"))
comments = Array(Request.Form("comments"))

'* Pull in form arrays
For i=0 to ubound(pub)
Response.Write "Item #: " & pub(i) & "
" & vbCrLf
next

For i=0 to ubound(qty)
Response.Write "Qty #: " & qty(i) & "
" & vbCrLf
next

For i=0 to ubound(comments)
Response.Write "Comments: " & comments(i) & "
" & vbCrLf
next

Re: Using Arrays from Javascript

am 20.12.2007 22:21:15 von reb01501

NoChat wrote:
________________________________________________________
> ASP CODE I'M USING TO TRY AND READ IN THIS INFORMATION
> ________________________________________________________
>
> Dim pub, qty, comments
>
> 'order information
> pub = Array(Request.Form("pub"))

? This does not make sense.

Do this to show us what is coming from your form:
<%
for each key in request.form
response.write key & ": " & request.form(key) & "
"
next
%>

--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"

Re: Using Arrays from Javascript

am 21.12.2007 11:57:27 von Daniel Crichton

NoChat wrote on Thu, 20 Dec 2007 12:37:53 -0800 (PST):

> 'order information
> pub = Array(Request.Form("pub"))
> qty = Array(Request.Form("qty"))
> comments = Array(Request.Form("comments"))

This just takes the contents of the Request items and puts them into an
array variable that has a single item.

eg.

myvar = Array("test")

creates an Array which has a single value at location 0.


> '* Pull in form arrays
> For i=0 to ubound(pub)
> Response.Write "Item #: " & pub(i) & "
" & vbCrLf
> next

> For i=0 to ubound(qty)
> Response.Write "Qty #: " & qty(i) & "
" & vbCrLf
> next

> For i=0 to ubound(comments)
> Response.Write "Comments: " & comments(i) & "
" & vbCrLf
> next

What does the output look like?

I'm guessing you need to use Split to break up a string into items based on
a delimiter.

eg.

myvar = Split("test1,test2",",")

will result in an array with 2 items, "test1" at location 0 and "test2" at
location 1.

However, you might find that this is already done for you if the data is
posted as fields with the same name. You can check this using the .Count
property, eg.

If Request.Form("pub").Count > 1 Then
'there are multiple items, which means they were posted all with the
same field name and have been automatically split up in the Request
collection
End If

--
Dan

Re: Using Arrays from Javascript

am 21.12.2007 16:14:51 von NoChat

On Dec 20, 4:21 pm, "Bob Barrows [MVP]"
wrote:
> NoChat wrote:
>
> ________________________________________________________
>
> > ASP CODE I'M USING TO TRY AND READ IN THIS INFORMATION
> > ________________________________________________________
>
> > Dim pub, qty, comments
>
> > 'order information
> > pub = Array(Request.Form("pub"))
>
> ? This does not make sense.
>
> Do this to show us what is coming from your form:
> <%
> for each key in request.form
> response.write key & ": " & request.form(key) & "
"
> next
> %>
>
> --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"

Thanks for all your help guys... Bob, I tried what you said. Here's
what I got :

qty[]: qty1, qty2, qty3
pub[]: pub1, pub2, pub3
comments[]: com1, com2, com3
Submit: Submit

Re: Using Arrays from Javascript

am 21.12.2007 21:18:44 von reb01501

NoChat wrote:
>>
> qty[]: qty1, qty2, qty3
> pub[]: pub1, pub2, pub3
> comments[]: com1, com2, com3
> Submit: Submit

OK, so now you want to put these results into arrays? Basically, just do
what Daniel said:
pub = Split(Request.Form("pub[]"),",")
qty = Split(Request.Form("qty[]"),","")


--
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"

Re: Using Arrays from Javascript

am 27.12.2007 14:51:50 von NoChat

On Dec 21, 3:18 pm, "Bob Barrows [MVP]"
wrote:
> NoChat wrote:
>
> > qty[]: qty1, qty2, qty3
> > pub[]: pub1, pub2, pub3
> > comments[]: com1, com2, com3
> > Submit: Submit
>
> OK, so now you want to put these results into arrays? Basically, just do
> what Daniel said:
> pub = Split(Request.Form("pub[]"),",")
> qty = Split(Request.Form("qty[]"),","")
>
> --
> 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"

Guys,

Thanks for your help. I've just about got it working the way I need.
My apologies if my questions were ridiculous -- I don't have much
experience with arrays.

One more question: The items being stored in my arrays need to be
emailed to somebody. I have the email script working properly, so
that's not the issue. The problem is that I'm storing the body text
(and formatting it) for that email message in a variable called
"Bodytext" and I can't seem to incorporate my arrays into that.
Obviously, I need to build some sort of loop that outputs everything,
and I can't just do a simple Response.Write because that doesn't work
for this purpose. Any suggestions for getting these arrays to work
with that variable?

Re: Using Arrays from Javascript

am 27.12.2007 15:09:50 von reb01501

NoChat wrote:
> Guys,
>
> Thanks for your help. I've just about got it working the way I need.
> My apologies if my questions were ridiculous -- I don't have much
> experience with arrays.
>
> One more question: The items being stored in my arrays need to be
> emailed to somebody. I have the email script working properly, so
> that's not the issue. The problem is that I'm storing the body text
> (and formatting it) for that email message in a variable called
> "Bodytext" and I can't seem to incorporate my arrays into that.
> Obviously, I need to build some sort of loop that outputs everything,
> and I can't just do a simple Response.Write because that doesn't work
> for this purpose. Any suggestions for getting these arrays to work
> with that variable?

I haven't a clue what you're trying to do, but I will hazard a guess
that the Join method may be what you are after:
http://msdn2.microsoft.com/en-us/library/yscc53h0.aspx

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.