Prevent unwanted comma

M

Morris

This may not be possible on the server side, so apologies if this is the
wrong group for this post.

My form consists of an unknown number of pairs of text boxes. They are
named textbox_a and textbox_b. I then split the comma separated list
that gets posted:

textbox_a = split(Request.Form("textbox_a"),",")
for i = ubound(textbox_a)
...insert into db

then do the same for textbox_b

If anyone puts a comma into one of the text boxes, this will result in
unmatched pairs. How can I deal with the comma, or prevent it?

Morris
 
R

Rob Meade

...
This may not be possible on the server side, so apologies if this is the
wrong group for this post.

Hello Morris,

It would be possible server side, but I think by then for you it would be
too late...what you want to do is prevent the comma's being entered at all
(if I read your post correctly)..

Try this:

http://javascript.internet.com/forms/block-press-script.html

It's blocking more characters than perhaps you need, I don't know - but it
might help, and would only need a little editing...

Another thing you could do would be to genereate unique id's for the boxes
instead...

I don't know what you're doing to create the form in the first place, but
you mentioned that its an "unknown number of text boxes" which to me
suggests that you have a loop of some sorts iterating through generating the
form, if this is the case, why not create a unique name on the fly, so
instead of just "textbox_a", you stick a number on the end, ie,
"textbox_a1", "textbox_a2"...etc, using the numbers from your iterating
loop.

The next part of course is working out how many were submitted so you can
get the values out using your request.form once the form is posted....couple
of ways...

1. after the iteration, write a hidden element with the total number of
iterations, pass this through and use it to parse the request.form the other
side...

ie,

<input type="hidden" name="iterations" value="<%=intIterations%>">

Then...once submitted..

intIterations = Request.Form("iterations")

For intLoop = 0 To intIterations

strFormElementName = "textbox_a" & intLoop

Request.Form(strFormElementName)

Next

Alternatively, you could get the ENTIRE request.form collection, and then do
the reverse, ie, whilst looping through the collection, ignore any other
fields that dont start with "textbox_a" or "textbox_b"...

Either would work, I've used both in practice in the past..

Hope this is of some use.

Regards

Rob
 
R

Roland Hall

in message
: "Morris" wrote ...
:
: > This may not be possible on the server side, so apologies if this is the
: wrong group for this post.
:
: Hello Morris,
:
: It would be possible server side, but I think by then for you it would be
: too late...what you want to do is prevent the comma's being entered at all
: (if I read your post correctly)..
:
: Try this:
:
: http://javascript.internet.com/forms/block-press-script.html
:
: It's blocking more characters than perhaps you need, I don't know - but it
: might help, and would only need a little editing...
:
: Another thing you could do would be to genereate unique id's for the boxes
: instead...
:
: I don't know what you're doing to create the form in the first place, but
: you mentioned that its an "unknown number of text boxes" which to me
: suggests that you have a loop of some sorts iterating through generating
the
: form, if this is the case, why not create a unique name on the fly, so
: instead of just "textbox_a", you stick a number on the end, ie,
: "textbox_a1", "textbox_a2"...etc, using the numbers from your iterating
: loop.
:
: The next part of course is working out how many were submitted so you can
: get the values out using your request.form once the form is
posted....couple
: of ways...
:
: 1. after the iteration, write a hidden element with the total number of
: iterations, pass this through and use it to parse the request.form the
other
: side...
:
: ie,
:
: <input type="hidden" name="iterations" value="<%=intIterations%>">
:
: Then...once submitted..
:
: intIterations = Request.Form("iterations")
:
: For intLoop = 0 To intIterations
:
: strFormElementName = "textbox_a" & intLoop
:
: Request.Form(strFormElementName)
:
: Next
:
: Alternatively, you could get the ENTIRE request.form collection, and then
do
: the reverse, ie, whilst looping through the collection, ignore any other
: fields that dont start with "textbox_a" or "textbox_b"...
:
: Either would work, I've used both in practice in the past..

Or, since your text fields are of unknown quantity, append an index to the
end of them so they each have a unique name. You can pass a hidden field
with the total number of fields and then use that as your max number of
items (-1) once posted. This eliminates the need to use client side code.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
M

Mark Schupp

Use array syntax to extract your data.

For i = 1 to request.form("textbox_a").count
texta = request.form("textbox_a")(i)
textb = request.form("textbox_b")(i)

'use the data for something

next
 
M

Morris

Roland said:
in message
: "Morris" wrote ...
:
: > This may not be possible on the server side, so apologies if this is the
: wrong group for this post.
:
: Hello Morris,
:
: It would be possible server side, but I think by then for you it would be
: too late...what you want to do is prevent the comma's being entered at all
: (if I read your post correctly)..
:
: Try this:
:
: http://javascript.internet.com/forms/block-press-script.html
:
: It's blocking more characters than perhaps you need, I don't know - but it
: might help, and would only need a little editing...
:
: Another thing you could do would be to genereate unique id's for the boxes
: instead...
:
: I don't know what you're doing to create the form in the first place, but
: you mentioned that its an "unknown number of text boxes" which to me
: suggests that you have a loop of some sorts iterating through generating
the
: form, if this is the case, why not create a unique name on the fly, so
: instead of just "textbox_a", you stick a number on the end, ie,
: "textbox_a1", "textbox_a2"...etc, using the numbers from your iterating
: loop.
:
: The next part of course is working out how many were submitted so you can
: get the values out using your request.form once the form is
posted....couple
: of ways...
:
: 1. after the iteration, write a hidden element with the total number of
: iterations, pass this through and use it to parse the request.form the
other
: side...
:
: ie,
:
: <input type="hidden" name="iterations" value="<%=intIterations%>">
:
: Then...once submitted..
:
: intIterations = Request.Form("iterations")
:
: For intLoop = 0 To intIterations
:
: strFormElementName = "textbox_a" & intLoop
:
: Request.Form(strFormElementName)
:
: Next
:
: Alternatively, you could get the ENTIRE request.form collection, and then
do
: the reverse, ie, whilst looping through the collection, ignore any other
: fields that dont start with "textbox_a" or "textbox_b"...
:
: Either would work, I've used both in practice in the past..

Or, since your text fields are of unknown quantity, append an index to the
end of them so they each have a unique name. You can pass a hidden field
with the total number of fields and then use that as your max number of
items (-1) once posted. This eliminates the need to use client side code.
Roland,

Belated thanks for your reply. I didn't use the javascript (although
I've added it to my snippets!) because your assumptions concerning how I
generate the form were spot on. I implemented your first server-side
suggestion - got rid of the arrays and reduced my code by 60%. Perfect.
 
R

Roland Hall

: Roland Hall wrote:
: > Or, since your text fields are of unknown quantity, append an index to
the
: > end of them so they each have a unique name. You can pass a hidden
field
: > with the total number of fields and then use that as your max number of
: > items (-1) once posted. This eliminates the need to use client side
code.
: >
: Roland,
:
: Belated thanks for your reply. I didn't use the javascript (although
: I've added it to my snippets!) because your assumptions concerning how I
: generate the form were spot on. I implemented your first server-side
: suggestion - got rid of the arrays and reduced my code by 60%. Perfect.

You're welcome. Glad to hear you got something working.
Merry Christmas.

Roland
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top