View Full Version : Can the delimter returned in a <SELECT> list be changed?
07-02-2003, 03:14 PM
If you have a <SELECT with MULTIPLE selects, what is
returned on posting is delimited (separated) by comma & space.
Is there anyway to change this delimiter? I know in perl
you can change the delimter of an array. Right now this
isn't an issue, since none of my .values have commas in
them, but if they did, I wouldn't be able to tell which
comma belonged and which did not. I did an IE test,
and it did NOT quote any fields with the delimiter in them.
For now, I have a routine that goes through and changes
anys commas to a predefined character. But I'd rather not
waste time scanning select lists.
An example: If I had a select list with "1" "2" & "3" selected
what is returned is: 1, 2, 3
If the select list were "1,2" "4,5" & "8,9" what would be
returned would be: 1,2, 4,5, 8,9
If I were trying to parse this list based on commas, It would
be almost impossible to get the correct data.
07-02-2003, 04:06 PM
i'm thinking this isn't possible. sorry.
07-02-2003, 06:42 PM
You are talking about what the server actually receives, yes? I agree w/joh6nn, no way to change that.
You could, however, use JS to populate a hidden input with the selected values delimited by a character of your choosing, onsubmit of the form. A bit hacky, but it could work.
07-02-2003, 07:13 PM
I'd rather change the actual data to a non-used character
like my routine does now, one less field to send back :)
That's one of the big differences between WORD and
EXCEL when you save a comma delimited file.
WORD just sticks comma between them,
EXCEL on the other hand looks at the data, if there
is a comma, it then quotes the field.
Thanks, just checking to see if anyone had any way
of actually changing the delimiter vs changing the
data, although creating the hidden field isn't a
bad way either, since it wouldn't require anything
server side to convert the non used character back
07-02-2003, 07:37 PM
I don't know what serverside language you use, but in PHP, if you name the multiple select list like test it indicates to the receiving PHP script that the values shall be put in an array - and there's no problem with commas within the option values, all comes neatly out in separate array elements. Absolutely no hassle with that.
07-02-2003, 07:53 PM
It's a perl .cgi that receives the posted data.
Does the browser behave differently if the program
recieiving isn't a .cgi. I thought a post was a post.
the delimiter appears to be ", " comma space.
I dont work in PHP so I can't test it. Be intrested
to see if it works with a comma-space in the
07-02-2003, 08:06 PM
How do you have your select list named? I just toyed a little with the list's name, and guess what, the  brackets apparently force the user agent to send a slightly different HTTP post content. With the brackets, a url-encoded list of all selected values from the last are sent, without the brackets, only one value appears.
Surely you can access raw POST data in Perl, and from this data reconstruct your single comma-infested values? I don't know Perl enough so I can't help you on that topic, but maybe the people in the CGI/Perl forum can.
07-02-2003, 08:19 PM
I must be missing something here...
What do you mean by 's in the name?
My HTML is setup:
<SELECT NAME="SOMETHING" MULTIPLE=MULTIPLE SIZE=3>
Then I use Javscript to add new values/codes to the Select
list, and prior to submitting the form, I have a function that
goes through and sets the select on each of the elements.
What does your raw data look like?
07-02-2003, 08:37 PM
I meant it like this:
<SELECT NAME="SOMETHING" MULTIPLE=MULTIPLE SIZE=3>
and the raw post data that gets sent (verified it with Mozillas LiveHTTPHeaders utility) was:
which decodes, by help of PHPs builtin rawurldecode() function, into:
and this string is later transformed into an array by PHP - you see, no confusion due to commas.
07-02-2003, 08:41 PM
HUH? I never heard of putting 's into the name for
any reason before. I'll have to see what happens.
07-02-2003, 08:48 PM
When I changed my NAME = "SALESTO"
and that gave me an error
07-02-2003, 08:51 PM
07-02-2003, 09:09 PM
OK. I see what it's doing.
I had to look at the raw raw data, my perl program
automagically converts the %## to their ASCII
equiv's so it still looked like commas to me :)
So it (browser) doesn't convert delimiting commas
to %2C, but does convert commas within the data
That will work.:thumbsup:
Now I'll have to recheck my raw raw data again
the original way and see if it did it that way as
I forgot my .cgi did that little conversion for me, so
it the comma always looked like a comma :D
07-02-2003, 11:35 PM
that was brilliant, Mordred. i would never have thought of that.
07-03-2003, 12:03 AM
joh6nn, I feel flattered. :o
My curiosity was sparked because I recently developed a PHP script that processed a similar multiple select list and as I said, it worked out of the box. So ggallens problem struck me as weird. Honestly, I didn't know that the brackets were the decisive key to this riddle, I just found out by watching the communication between Mozilla and a little PHP test script.
For whom it may concern, to debug cases like this the plugin LiveHTTPHeaders (http://livehttpheaders.mozdev.org/) is a real life-saver. It's pretty to install too. I recommend it very much.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.