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

Nick Fitzsimons nick at nickfitz.co.uk
Wed Nov 29 07:25:37 CST 2006


On 29 Nov 2006, at 13:04:18, John Deighan wrote:

> 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:
>
> 	name=value1,value2,...,valuen
>
> 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:
>
> 	name=1&name=2&name=3
>
> 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:
>
> 	name=1,2
>
> and the second is sent as:
>
> 	name=1%2C2
>
> 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.
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript

Although the relevant part <http://tools.ietf.org/html/ 
rfc3986#section-3.4> of RFC 3986 "URI: Generic Syntax" does not  
explicitly require the "thing=value&thing=value2" format (it merely  
mentions that "query components are often used to carry identifying  
information in the form of "key=value" pairs"), that is the way that  
all browsers I've ever come across use it.

If Ethereal seems like too much hassle (which it is for simply  
sniffing HTTP traffic) and you're running Windows, give Fiddler  
<http://www.fiddlertool.com/> a try. I've already described it in  
more detail in a post to the thread "pb with httprequest and Firefox"  
earlier today, so I'll refer you there rather than repeating myself;  
suffice it to say that it will allow you to see precisely what's  
being sent over the wire with no hassle at all.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/






More information about the Javascript mailing list