[thelist] Escape of the Commas!

Cymbala, Greg Greg.Cymbala at Den.Galileo.com
Tue Jun 25 15:21:00 CDT 2002

If you want, you can use JavaScript to do some escaping or replacing of
commas in the values before the form is submitted.  Or, you can handle it
server-side, like this (watch for line-wrap):

<form name="frmMyForm" method="POST">
<input type="checkbox" name="myCheckbox" value="1,2,3"
	checked="true" /> myCheckbox (1)<br />
<input type="checkbox" name="myCheckbox" value="3,4,5"
	checked="true" /> myCheckbox (2)<br />
<input type="checkbox" name="myCheckbox" value="7,8,9"
	checked="true" /> myCheckbox (3)<br />

Dim i, oDictionary, arrMyArray

If Request.Form("myCheckbox").Count > 1 Then
	Set oDictionary = Server.CreateObject("Scripting.Dictionary")
	For i = 1 To Request.Form("myCheckbox").Count
		If Not oDictionary.Exists(i) Then
			oDictionary.Add i, Request.Form("myCheckbox")(i)
		End If
	arrMyArray = oDictionary.Items()
	Set oDictionary = Nothing
	arrMyArray = Array(Request.Form("myCheckbox"))
End If

For i = LBound(arrMyArray) To UBound(arrMyArray)
	Response.Write("<p>Posted value of arrMyArray(" & i & ") = ")
	Response.Write(arrMyArray(i) & "</p>")

<input type="submit" value="Submit" name="btnSubmit" />

I know there's some overhead, with the creation of the dictionary object,
and looping through twice, but it keeps you from relying on JavaScript,
which can be a plus.  Also, this will work whether there's only one form
element called "myCheckbox" or twenty.


-----Original Message-----
From: Ken Kogler [mailto:ken.kogler at cph.org]
Sent: Tuesday, June 25, 2002 1:51 PM
To: thelist
Subject: [thelist] Escape of the Commas!

Sounds like a cheesy B-movie title, but it pertains to my question:

I've got multiple form elements (checkboxes, in this case) with the same
name. Sometimes, their values contain commas. I'd like to escape or replace
these commas somehow, but I can't find an equivalent. (double quotes are
&quot;, left angle brackets are &lt;, etc, but what are commas? Is there
even a character entity for a comma?)

If I do request.form("myCheckbox"), I get back a comma-delineated list of
all the values (e.g. "value1, value2, value3"). I want to split this into an
array based on those commas, but if one of the values was "val,ue4", this
would wreck what I'm doing... see my problem?

Anyone know how to escape those pesky comma values?


The information in this electronic mail message is sender's business
Confidential and may be legally privileged.  It is intended solely for the
addressee(s).  Access to this Internet electronic mail message by anyone
else is unauthorized.  If you are not the intended recipient, any
disclosure, copying, distribution or any action taken or omitted to be taken
in reliance on it is prohibited and may be unlawful.
The sender believes that this E-mail and any attachments were free of any
virus, worm, Trojan horse, and/or malicious code when sent. This message and
its attachments could have been infected during  transmission. By reading
the message and opening any attachments, the recipient accepts full
responsibility for taking protective and remedial action about viruses and
other defects. Galileo International is not liable for any loss or damage
arising in any way from this message or its attachments.

More information about the thelist mailing list