Prevent unwanted comma

Discussion in 'ASP General' started by Morris, Dec 12, 2004.

  1. Morris

    Morris Guest

    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, Dec 12, 2004
    #1
    1. Advertising

  2. Morris

    Rob Meade Guest

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

    Hope this is of some use.

    Regards

    Rob
     
    Rob Meade, Dec 12, 2004
    #2
    1. Advertising

  3. Morris

    Roland Hall Guest

    "Rob Meade" wrote in message
    news:0%%ud.35737$...
    : "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
     
    Roland Hall, Dec 13, 2004
    #3
  4. Morris

    Mark Schupp Guest

    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" <> wrote in message
    news:FK%ud.13413$...
    > 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
     
    Mark Schupp, Dec 13, 2004
    #4
  5. Morris

    Morris Guest

    Roland Hall wrote:
    > "Rob Meade" wrote in message
    > news:0%%ud.35737$...
    > : "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.
     
    Morris, Dec 24, 2004
    #5
  6. Morris

    Roland Hall Guest

    "Morris" <> wrote in message
    news:xJPyd.43260$...
    : 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
     
    Roland Hall, Dec 25, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BobLeavitt

    .NET 1.1 created unwanted logon screen

    BobLeavitt, Jun 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    686
    Mark Broadbent
    Jun 21, 2005
  2. Kevin Chandler

    Unwanted Refresh/Redraw

    Kevin Chandler, Jan 29, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    3,197
    Charlie Nilsson [MSFT]
    Jan 29, 2004
  3. sanjay patil via .NET 247

    Previous(Unwanted) event handled when page refreshed by key F5

    sanjay patil via .NET 247, Apr 27, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    417
    sanjay patil via .NET 247
    Apr 27, 2004
  4. DC Gringo

    panel inserted unwanted div tag

    DC Gringo, Sep 23, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    445
    Alan Ferrandiz [MCT]
    Sep 23, 2004
  5. PW

    Unwanted Comma

    PW, May 20, 2004, in forum: ASP General
    Replies:
    3
    Views:
    99
    Larry Bud
    May 20, 2004
Loading...

Share This Page