Split Textarea (by lines), trim and save to Database
Hi,
I want to know if it is possible to do the following.
I have a form which lets users select a product, enter a quantity and
set the info into a Textarea field.
Each time the user hits the 'Set' button, it adds another line into
the Textarea, e.g.
______________________
5 x Product1
63 x Product2
115 x Product3
75 x Product 7
______________________
At present, I just have the data sent in an email, but now I need to
save each line into our database, linked to a specific PO Number.
Is there a way to strip the data in the Textarea into variables on the
next page like
Within a loop which runs through each line
Strip the product code and qty
Product Code = Product1
Product Qty = 5
Load Product Code & Product Qty into the Database
where ...........................
Then go to the next line and load into database
Appreciate your help on this
David
Re: Split Textarea (by lines), trim and save to Database
"David" <davidgordon [at] scene-double.co.uk> wrote in message
news:1190130282.701564.55390 [at] z24g2000prh.googlegroups.com...
> Hi,
>
> I want to know if it is possible to do the following.
>
> I have a form which lets users select a product, enter a quantity and
> set the info into a Textarea field.
> Each time the user hits the 'Set' button, it adds another line into
> the Textarea, e.g.
>
> ______________________
> 5 x Product1
> 63 x Product2
> 115 x Product3
> 75 x Product 7
> ______________________
>
> At present, I just have the data sent in an email, but now I need to
> save each line into our database, linked to a specific PO Number.
> Is there a way to strip the data in the Textarea into variables on the
> next page like
>
> Within a loop which runs through each line
> Strip the product code and qty
>
> Product Code = Product1
> Product Qty = 5
Will this get you started:
<textarea name="your_textarea" rows="10" cols="40"></textarea>
<%
Option Explicit
Dim arrORD()
Dim intORD
Dim strORD
strORD = Request.Form("your_textarea")
If strORD <> "" Then
arrORD = Split(strORD," x ")
For intORD = 0 To UBound(arrORD)
Response.Write _
" Product Code = " & arrORD(0) _
" Product Qty = " & arrORD(1)
Next
End If
%>
>
> Load Product Code & Product Qty into the Database
> where ...........................
>
> Then go to the next line and load into database
What database?
Re: Split Textarea (by lines), trim and save to Database
"McKirahan" <News [at] McKirahan.com> wrote in message
news:PImdnUxAhuhdZXLbnZ2dneKdnZydnZ2d [at] comcast.com...
> "David" <davidgordon [at] scene-double.co.uk> wrote in message
> news:1190130282.701564.55390 [at] z24g2000prh.googlegroups.com...
> > Hi,
> >
> > I want to know if it is possible to do the following.
> >
> > I have a form which lets users select a product, enter a quantity and
> > set the info into a Textarea field.
> > Each time the user hits the 'Set' button, it adds another line into
> > the Textarea, e.g.
> >
> > ______________________
> > 5 x Product1
> > 63 x Product2
> > 115 x Product3
> > 75 x Product 7
> > ______________________
> >
> > At present, I just have the data sent in an email, but now I need to
> > save each line into our database, linked to a specific PO Number.
> > Is there a way to strip the data in the Textarea into variables on the
> > next page like
> >
> > Within a loop which runs through each line
> > Strip the product code and qty
> >
> > Product Code = Product1
> > Product Qty = 5
>
> Will this get you started:
>
> <textarea name="your_textarea" rows="10" cols="40"></textarea>
>
> <%
> Option Explicit
> Dim arrORD()
> Dim intORD
> Dim strORD
> strORD = Request.Form("your_textarea")
> If strORD <> "" Then
> arrORD = Split(strORD," x ")
> For intORD = 0 To UBound(arrORD)
> Response.Write _
> " Product Code = " & arrORD(0) _
> " Product Qty = " & arrORD(1)
> Next
> End If
> %>
>
> >
> > Load Product Code & Product Qty into the Database
> > where ...........................
> >
> > Then go to the next line and load into database
>
> What database?
>
Oops:
Response.Write _
" Product Code = " & arrORD(1) _
" Product Qty = " & arrORD(0)
Re: Split Textarea (by lines), trim and save to Database
"David" <davidgordon [at] scene-double.co.uk> wrote in message
news:1190130282.701564.55390 [at] z24g2000prh.googlegroups.com...
> Hi,
>
> I want to know if it is possible to do the following.
>
> I have a form which lets users select a product, enter a quantity and
> set the info into a Textarea field.
> Each time the user hits the 'Set' button, it adds another line into
> the Textarea, e.g.
>
> ______________________
> 5 x Product1
> 63 x Product2
> 115 x Product3
> 75 x Product 7
> ______________________
>
> At present, I just have the data sent in an email, but now I need to
> save each line into our database, linked to a specific PO Number.
> Is there a way to strip the data in the Textarea into variables on the
> next page like
>
> Within a loop which runs through each line
> Strip the product code and qty
>
> Product Code = Product1
> Product Qty = 5
>
>
>
>
> Load Product Code & Product Qty into the Database
> where ...........................
>
> Then go to the next line and load into database
>
> Appreciate your help on this
>
> David
>
You can use the textrange object
http://msdn2.microsoft.com/en-us/library/ms533042.aspx
but it would be easier to use a array to hold values not the textarea
Re: Split Textarea (by lines), trim and save to Database
David <davidgordon [at] scene-double.co.uk> wrote:
>Hi,
>
>I want to know if it is possible to do the following.
>
>I have a form which lets users select a product, enter a quantity and
>set the info into a Textarea field.
>Each time the user hits the 'Set' button, it adds another line into
>the Textarea, e.g.
>
>______________________
>5 x Product1
>63 x Product2
>115 x Product3
>75 x Product 7
>______________________
>
>At present, I just have the data sent in an email, but now I need to
>save each line into our database, linked to a specific PO Number.
>Is there a way to strip the data in the Textarea into variables on the
>next page like
>
>Within a loop which runs through each line
>Strip the product code and qty
>
>Product Code = Product1
>Product Qty = 5
Aren't the lines separated by newline characters? Then - assuming your
ASP page is using VBScript - use the Split function
(http://msdn2.microsoft.com/en-us/library/0764e5w5.aspx) to break the
contents of the textarea into individual lines. If you using
Javascript to write your ASP code, it's the split method of the String
object (http://msdn2.microsoft.com/en-us/library/t5az126b.aspx)
--
Tim Slattery
MS MVP(DTS)
Slattery_T [at] bls.gov
http://members.cox.net/slatteryt
Re: Split Textarea (by lines), trim and save to Database
"McKirahan" <News [at] McKirahan.com> wrote in message
news:GoGdneUEls1lZXLbnZ2dnUVZ_gydnZ2d [at] comcast.com...
> "McKirahan" <News [at] McKirahan.com> wrote in message
> news:PImdnUxAhuhdZXLbnZ2dneKdnZydnZ2d [at] comcast.com...
> > "David" <davidgordon [at] scene-double.co.uk> wrote in message
> > news:1190130282.701564.55390 [at] z24g2000prh.googlegroups.com...
> > > Hi,
> > >
> > > I want to know if it is possible to do the following.
> > >
> > > I have a form which lets users select a product, enter a quantity and
> > > set the info into a Textarea field.
> > > Each time the user hits the 'Set' button, it adds another line into
> > > the Textarea, e.g.
> > >
> > > ______________________
> > > 5 x Product1
> > > 63 x Product2
> > > 115 x Product3
> > > 75 x Product 7
> > > ______________________
> > >
> > > At present, I just have the data sent in an email, but now I need to
> > > save each line into our database, linked to a specific PO Number.
> > > Is there a way to strip the data in the Textarea into variables on the
> > > next page like
> > >
> > > Within a loop which runs through each line
> > > Strip the product code and qty
> > >
> > > Product Code = Product1
> > > Product Qty = 5
> >
> > Will this get you started:
[snip]
Oops, again. Try this:
<html>
<head>
<title>Products.htm</title>
<script type="text/vbscript">
Option Explicit
Sub Products()
Dim arrORD
Dim intORD
Dim strORD
strORD = document.getElementById("area").value
Dim arrPRD
If strORD <> "" Then
arrORD = Split(strORD,vbCrLf)
For intORD = 0 To UBound(arrORD)
arrPRD = Split(arrORD(intORD)," x ")
Alert " Product Code = " & arrPRD(1) & " Product Qty = " &
arrPRD(0)
Next
End If
End Sub
</script>
</head>
<body>
<form action="" method="get">
<textarea name="area" rows="10" cols="40"></textarea>
<input type="button" value="Click" onclick="Products()">
</form>
</body>
</html>