IIS ASP - Prevent unwanted comma

This is Interesting: Free IT Magazines  
Home > Archive > IIS ASP > December 2004 > Prevent unwanted comma





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Prevent unwanted comma
Morris

2004-12-12, 6:36 pm

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
Rob Meade

2004-12-12, 6:36 pm

"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/form...ess-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


Roland Hall

2004-12-13, 3:37 am

"Rob Meade" wrote in message
news:0%%ud.35737$up1.4132@text.news.blueyonder.co.uk...
: "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/form...ess-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


Mark Schupp

2004-12-13, 6:38 pm

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


--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com


"Morris" <keepingmyinboxclear@last.thanks> wrote in message
news:FK%ud.13413$qr4.1576@fe2.news.blueyonder.co.uk...
> 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



Morris

2004-12-24, 3:02 am

Roland Hall wrote:
> "Rob Meade" wrote in message
> news:0%%ud.35737$up1.4132@text.news.blueyonder.co.uk...
> : "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/form...ess-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.
Roland Hall

2004-12-25, 4:51 am

"Morris" <nospam@thanks.com> wrote in message
news:xJPyd.43260$ef5.28706@fe1.news.blueyonder.co.uk...
: 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


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com