[Javascript] error in "JavaScript: The Definitive Guide"?

John Deighan jdeighan at pcgus.com
Wed Nov 29 07:04:18 CST 2006

I think I've found an error in the JavaScript book I use the most. 
Before reporting it to O'Reilly, though, I thought I'd pass it by 
some of the JavaScript gurus on this list. The book says:

For input elements of type "radio" and "checkbox", it is common to 
define more than one related object, each of which have the same 
'name' property. In this case, data is submitted to the server with 
this format:


I've checked with a simple HTML page that submits to a Perl script, 
and the query string that the script receives has duplicate entries 
with the same name, like this:


including only those values where the checkbox was actually checked. 
I checked both IE and FF, and, in fact, I've programmed functions 
that split a query string and this is the way it was always done. 
Also, I think this is the correct way, though it does lead to 
problems if you try to put the values of CGI variables into a hash, 
because a hash can have only one entry for each key. You might say 
that in that case, you could put the values into a list, but there's 
no way to know if the original form had multiple checkboxes, but the 
user only checked one, so that would still give programmers headaches 
since they would expect a list, but not get one. Anyway, I digress...

I guess what I'm not positive about is whether the data is actually 
sent in the first form, but the CGI subsystem converts it to the 
second form before passing it to my Perl script. At first I thought 
that that could not be the case since I'm able to distinguish whether 
two checkboxes with the values '1' and '2' were checked, from the 
case where a single checkbox with the value '1,2' was checked. 
However, when I tried it I realized that a comma in a checkbox's 
value would be escaped, so it's possible that the first case is sent as:


and the second is sent as:


so they could be distinguished. So, does anyone know what's really 
going on here?

P.S. I guess I could figure this out myself if I knew how to use a 
packet sniffer like Ethereal. I have it, but never found the time to 
figure it out.

More information about the Javascript mailing list