Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-02-2003, 03:14 PM   PM User | #1
ggallen
Regular Coder

 
Join Date: Jul 2003
Location: NJ - #29 if you must know
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
ggallen is an unknown quantity at this point
Can the delimter returned in a <SELECT> list be changed?

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.

Thanks
George
ggallen is offline   Reply With Quote
Old 07-02-2003, 04:06 PM   PM User | #2
joh6nn
wei wu wei


 
joh6nn's Avatar
 
Join Date: Jun 2002
Location: 72° W. 48' 57" , 41° N. 32' 04"
Posts: 1,887
Thanks: 0
Thanked 1 Time in 1 Post
joh6nn is an unknown quantity at this point
i'm thinking this isn't possible. sorry.
__________________
bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

i am a loser geek, crazy with an evil streak,
yes i do believe there is a violent thing inside of me.
joh6nn is offline   Reply With Quote
Old 07-02-2003, 06:42 PM   PM User | #3
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
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.
__________________
My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
“Minds are like parachutes. They don't work unless they are open”
“Maturity is simply knowing when to not be immature”
beetle is offline   Reply With Quote
Old 07-02-2003, 07:13 PM   PM User | #4
ggallen
Regular Coder

 
Join Date: Jul 2003
Location: NJ - #29 if you must know
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
ggallen is an unknown quantity at this point
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.

Maybe on the next javascript version, it will quote the
fields.

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
to comma's.

George
ggallen is offline   Reply With Quote
Old 07-02-2003, 07:37 PM   PM User | #5
mordred
Senior Coder


 
Join Date: Jun 2002
Location: frankfurt, german banana republic
Posts: 1,848
Thanks: 0
Thanked 0 Times in 0 Posts
mordred is an unknown quantity at this point
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.
__________________
De gustibus non est disputandum.
mordred is offline   Reply With Quote
Old 07-02-2003, 07:53 PM   PM User | #6
ggallen
Regular Coder

 
Join Date: Jul 2003
Location: NJ - #29 if you must know
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
ggallen is an unknown quantity at this point
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
data however.

George
ggallen is offline   Reply With Quote
Old 07-02-2003, 08:06 PM   PM User | #7
mordred
Senior Coder


 
Join Date: Jun 2002
Location: frankfurt, german banana republic
Posts: 1,848
Thanks: 0
Thanked 0 Times in 0 Posts
mordred is an unknown quantity at this point
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.
__________________
De gustibus non est disputandum.
mordred is offline   Reply With Quote
Old 07-02-2003, 08:19 PM   PM User | #8
ggallen
Regular Coder

 
Join Date: Jul 2003
Location: NJ - #29 if you must know
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
ggallen is an unknown quantity at this point
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>
</SELECT>

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?

George
ggallen is offline   Reply With Quote
Old 07-02-2003, 08:37 PM   PM User | #9
mordred
Senior Coder


 
Join Date: Jun 2002
Location: frankfurt, german banana republic
Posts: 1,848
Thanks: 0
Thanked 0 Times in 0 Posts
mordred is an unknown quantity at this point
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:

test%5B%5D=5%2C6&test%5B%5D=7%2C8

which decodes, by help of PHPs builtin rawurldecode() function, into:

test[]=5,6&test[]=7,8

and this string is later transformed into an array by PHP - you see, no confusion due to commas.
__________________
De gustibus non est disputandum.
mordred is offline   Reply With Quote
Old 07-02-2003, 08:41 PM   PM User | #10
ggallen
Regular Coder

 
Join Date: Jul 2003
Location: NJ - #29 if you must know
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
ggallen is an unknown quantity at this point
HUH? I never heard of putting []'s into the name for
any reason before. I'll have to see what happens.

Thanks
George
ggallen is offline   Reply With Quote
Old 07-02-2003, 08:48 PM   PM User | #11
ggallen
Regular Coder

 
Join Date: Jul 2003
Location: NJ - #29 if you must know
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
ggallen is an unknown quantity at this point
When I changed my NAME = "SALESTO[]"

my javascript didn't work...

So I changed my javascript to:

makeallselected(document.FORM1.SALESTO[]);

and that gave me an error

George
ggallen is offline   Reply With Quote
Old 07-02-2003, 08:51 PM   PM User | #12
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
makeallselected(document.FORM1.elements['SALESTO[]']);
__________________
My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
“Minds are like parachutes. They don't work unless they are open”
“Maturity is simply knowing when to not be immature”
beetle is offline   Reply With Quote
Old 07-02-2003, 09:09 PM   PM User | #13
ggallen
Regular Coder

 
Join Date: Jul 2003
Location: NJ - #29 if you must know
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
ggallen is an unknown quantity at this point
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
to %2C.

That will work.

Now I'll have to recheck my raw raw data again
the original way and see if it did it that way as
well.

I forgot my .cgi did that little conversion for me, so
it the comma always looked like a comma

George
ggallen is offline   Reply With Quote
Old 07-02-2003, 11:35 PM   PM User | #14
joh6nn
wei wu wei


 
joh6nn's Avatar
 
Join Date: Jun 2002
Location: 72° W. 48' 57" , 41° N. 32' 04"
Posts: 1,887
Thanks: 0
Thanked 1 Time in 1 Post
joh6nn is an unknown quantity at this point
that was brilliant, Mordred. i would never have thought of that.
__________________
bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

i am a loser geek, crazy with an evil streak,
yes i do believe there is a violent thing inside of me.
joh6nn is offline   Reply With Quote
Old 07-03-2003, 12:03 AM   PM User | #15
mordred
Senior Coder


 
Join Date: Jun 2002
Location: frankfurt, german banana republic
Posts: 1,848
Thanks: 0
Thanked 0 Times in 0 Posts
mordred is an unknown quantity at this point
joh6nn, I feel flattered.
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 is a real life-saver. It's pretty to install too. I recommend it very much.
__________________
De gustibus non est disputandum.
mordred is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:54 AM.


Advertisement
Log in to turn off these ads.