Prevent unwanted comma
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > IIS server support > IIS ASP > Prevent unwanted comma




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Prevent unwanted comma  
Morris


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-12-04 11: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





[ Post a follow-up to this message ]



    Re: Prevent unwanted comma  
Rob Meade


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-12-04 11: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







[ Post a follow-up to this message ]



    Re: Prevent unwanted comma  
Roland Hall


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-13-04 08: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







[ Post a follow-up to this message ]



    Re: Prevent unwanted comma  
Mark Schupp


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-13-04 11: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







[ Post a follow-up to this message ]



    Re: Prevent unwanted comma  
Morris


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-24-04 08: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 t
he
> : wrong group for this post.
> :
> : Hello Morris,
> :
> : It would be possible server side, but I think by then for you it would b
e
> : too late...what you want to do is prevent the comma's being entered at a
ll
> : (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 box
es
> : instead...
> :
> : I don't know what you're doing to create the form in the first place, bu
t
> : 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 ca
n
> : 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 the
n
> 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.





[ Post a follow-up to this message ]



    Re: Prevent unwanted comma  
Roland Hall


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-25-04 09: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







[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:01 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register