A New Type of Formation

  • kipthegreat 2006-08-30 13:46
    A selecter, huh?&nbsp; So what's the selectest!<br>
  • AndrewVos 2006-08-30 13:49
    <P>Dare I say "Javascript has the best WTF's" ?</P>
  • rmr 2006-08-30 13:52
    Rofl, so if I'm reading this right, if he has 10, 210, 310 and 410 checked, and he unchecks 10, he ends up with 234 checked?&nbsp; Good thing the ids are so high!<br><br>What does the g in the eval line do?<br>
  • kipthegreat 2006-08-30 13:54
    rmr:
    Rofl, so if I'm reading this right, if he has 10, 210, 310 and 410 checked, and he unchecks 10, he ends up with 234 checked?&nbsp; Good thing the ids are so high!<br><br>What does the g in the eval line do?<br>
    <br><br>g = global replace.&nbsp; otherwise, only the first "10," would be replaced.<br>
  • sammybaby 2006-08-30 13:55
    Alex Papadimoulis:
    <p>The root folder housed over 400 of
    files, most belonging to completely different modules. Actually, there
    was one subfolder: it contained all the code and pages for the previous
    programmer's World of Warcraft clan website. </p>
    <br>
    <br>
    I was originally going to make a joke about the javascript as an effort to make sure that the checked checkboxes were, like, <i>really checked</i>, so they didn't have a situation like the 2000 Florida vote with the hanging chads and whatnot.<br><br>Then I re-read the bit about the WoW site and though, aw, hell, that's funnier than anything I could come up with anyway.<br>
  • kipthegreat 2006-08-30 13:55
    I guess he is unfamiliar with $_POST in PHP?<br>
  • trippyz 2006-08-30 13:57
    Is it safe to remove my welding goggles yet?
  • CodeRage 2006-08-30 13:59
    kipthegreat:
    rmr:
    Rofl, so if I'm reading this right, if he has 10, 210, 310 and 410 checked, and he unchecks 10, he ends up with 234 checked?&nbsp; Good thing the ids are so high!<br>What does the g in the eval line do?<br>
    <br>g = global replace.&nbsp; otherwise, only the first "10," would be replaced.<br>
    <br>Yeah, this is awesome!&nbsp; For fun, paste this code on your machine at work, add some checkboxes where the ids are substrings of the other ids, and change the hidden input to text so you can see it as it messes up the list of ids.<br><br>And all this for something the browser does for you when it posts the form, had the developer been 1337 enough to give all the checkboxes the same name, with each value being the id.<br>
  • Digitalbath 2006-08-30 14:05
    <P>
    CodeRage:
    kipthegreat:
    rmr:
    Rofl, so if I'm reading this right, if he has 10, 210, 310 and 410 checked, and he unchecks 10, he ends up with 234 checked?&nbsp; Good thing the ids are so high!<BR>What does the g in the eval line do?<BR>
    <BR>g = global replace.&nbsp; otherwise, only the first "10," would be replaced.<BR>
    <BR>Yeah, this is awesome!&nbsp; For fun, paste this code on your machine at work, add some checkboxes where the ids are substrings of the other ids, and change the hidden input to text so you can see it as it messes up the list of ids.<BR><BR>And all this for something the browser does for you when it posts the form, had the developer been 1337 enough to give all the checkboxes the same name, with each value being the id.<BR>
    </P>
    <P>Yes, but then he wouldn't be able to handle "input" from mutliple pages in his insert.php file.&nbsp; At least that's what i'm guessing he did.&nbsp; Based on the prefix of fthe checkboxes, he probably had some huge switch statement in that file that knew what values were selected on what page.&nbsp; It's&nbsp;the new&nbsp;duct tape...insert.php!</P>
    <P>Or, am I completely off here?</P>
  • Digitalbath 2006-08-30 14:08
    <P>I did not interpret "in trouble" as getting fired.&nbsp; If he did not get fired for trying to sell proprietary software on eBay...that might be a bigger WTF than his whole system.</P>
  • merreborn 2006-08-30 14:18
    kipthegreat:
    I guess he is unfamiliar with $_POST in PHP?<br>
    <br><br>Unnecessary:&nbsp; assuming the point of this was to convert a POST to a GET, all he had to do was change<br>&lt;form method="POST"&gt; to &lt;form method="GET"&gt;<br><br><br>I'm pretty sure GET is the default anyway.&nbsp; I can't for the life of me figure out why the fuck he thought he needed the javascript.<br>
  • rocksanddirt 2006-08-30 14:18
    As javascript in itself was designed with good intentions, there are many facets about the language and the varying browser capabilities that can eventually drive your code into WTFland for the next developer...<br>
  • Gnictigezoink 2006-08-30 14:20
    Holy crap.<br><br>Err. Unholy Crap.<br><br>'Nother instance of "TTWTASO" design pattern (trash the whole thing and start over)<br>
  • wyz 2006-08-30 14:24
    <P>The story around it&nbsp;is differenct, or&nbsp;this could be&nbsp;jscript from the place I at now as an on-site contractor! </P>
    <P>This job was&nbsp;presumably modifying about 8 web pages.&nbsp;But it turned out the pages had server-side jscript rendering client-side jscript with this kind of garbage code, plus putting values in and out of XML strings by someone not knowing how to use XML. That just my rant on the web pages!&nbsp;</P>
    <P>In fact, some samples were submitted to WTF, but&nbsp;Alex only had sympathy for me. Don't recall if it was duplicate stuff or wasn't humorous enough to use. But it has kept some of my sanity reading WTF and seeing I'm not the only one dealing with bad coding and applications.</P>
    <P>(Someone had to ask real nice to get me to come&nbsp;here and rescue a project that was sinking.&nbsp;The first guy placed here couldn't figure out what to do.)</P>
    <P>&nbsp;</P>
  • Aximilation 2006-08-30 14:36
    Oh yes, forget the whole $_REQUEST.....very nice. I've always wanted to create the new and improved version of that. Lol...<br>It's almost as bad as the new link tag seen elsewhere on this site last week...<br>&lt;a onclick="location='http://www.aximilation.com'; return false;" href="#"&gt;The &lt;em&gt;new&lt;/em&gt; link!&lt;/a&gt;<br>(I'm making a t-shirt!)<br>
  • obediah 2006-08-30 14:41
    Digitalbath:
    <p>Yes, but then he wouldn't be able to handle "input" from mutliple pages in his insert.php file.&nbsp; At least that's what i'm guessing he did.&nbsp; Based on the prefix of fthe checkboxes, he probably had some huge switch statement in that file that knew what values were selected on what page.&nbsp; It's&nbsp;the new&nbsp;duct tape...insert.php!</p>
    <p>Or, am I completely off here?</p>
    <br><br>This is what happens when someone hears the term 'MVC' in passing and then reads a random blog post. Because nothing controls like a single file with 20,000 if statements.<br>
  • Anon 2006-08-30 14:41
    Alex Papadimoulis:

    <P><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">script</SPAN><SPAN style="COLOR: #ff0000"> type<SPAN style="COLOR: #0000ff">="text/javascript"</SPAN></SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">!--</SPAN><SPAN style="COLOR: #000000"><BR><BR>function onCheck(id)<BR>{<BR>&nbsp; checkedValues = document.selecter.checkedValues;<BR>&nbsp; checkedBox = document.selecter["check_"+id];<BR>&nbsp; <BR>&nbsp; if (!checkedBox.checked)<BR>&nbsp;&nbsp;&nbsp; checkedValues.value = <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; eval("checkedValues.value.replace(/" +id + ',' + "/g,'')");<BR>&nbsp; else<BR>&nbsp;&nbsp;&nbsp; <FONT size=4><STRONG>checkedValues.value+=(id+',');</STRONG><BR></FONT>}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>function submit()<BR>{<BR>&nbsp; document.location.href = 'insert.php?chosen=' + <BR>&nbsp;&nbsp;&nbsp;&nbsp; document.selecter.checkedValues.value;<BR>&nbsp; return false;<BR>}<BR><BR><BR>//--</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">script</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><BR><BR><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">form</SPAN><SPAN style="COLOR: #ff0000"> id<SPAN style="COLOR: #0000ff">="selecter"</SPAN> name<SPAN style="COLOR: #0000ff">="selecter"</SPAN></SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><BR>&nbsp; <SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">input</SPAN><SPAN style="COLOR: #ff0000"> type<SPAN style="COLOR: #0000ff">="hidden"</SPAN> id<SPAN style="COLOR: #0000ff">="checkedValues"</SPAN> name<SPAN style="COLOR: #0000ff">="checkedValues"</SPAN> </SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><BR>&nbsp; <SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">input</SPAN><SPAN style="COLOR: #ff0000"> class<SPAN style="COLOR: #0000ff">="button"</SPAN> type<SPAN style="COLOR: #0000ff">="button"</SPAN> value<SPAN style="COLOR: #0000ff">="Submit"</SPAN> onclick<SPAN style="COLOR: #0000ff">="submit()"</SPAN> </SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><BR><BR>&nbsp; <SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">input</SPAN><SPAN style="COLOR: #ff0000"> id<SPAN style="COLOR: #0000ff">="check_4273844"</SPAN> onclick<SPAN style="COLOR: #0000ff">="onCheck('4273844')"</SPAN> type<SPAN style="COLOR: #0000ff">="checkbox"</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<SPAN style="COLOR: #0000ff">="check_4273844"</SPAN> <STRONG><FONT size=4>value<SPAN style="COLOR: #0000ff">="ON"</SPAN></FONT></STRONG> </SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><BR>&nbsp; ...<BR>&nbsp; <SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">input</SPAN><SPAN style="COLOR: #ff0000"> id<SPAN style="COLOR: #0000ff">="check_4273843"</SPAN> onclick<SPAN style="COLOR: #0000ff">="onCheck('4273843')"</SPAN> type<SPAN style="COLOR: #0000ff">="checkbox"</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<SPAN style="COLOR: #0000ff">="check_4273843"</SPAN> <STRONG><FONT size=4>value<SPAN style="COLOR: #0000ff">="ON"</SPAN></FONT></STRONG> </SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><BR>&nbsp; ...<BR>&nbsp; <SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">input</SPAN><SPAN style="COLOR: #ff0000"> id<SPAN style="COLOR: #0000ff">="check_4273842"</SPAN> onclick<SPAN style="COLOR: #0000ff">="onCheck('4273842')"</SPAN> type<SPAN style="COLOR: #0000ff">="checkbox"</SPAN> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<SPAN style="COLOR: #0000ff">="check_4273842"</SPAN> <STRONG><FONT size=4>value<SPAN style="COLOR: #0000ff">="ON"</SPAN></FONT></STRONG> </SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><BR>&nbsp; ...<BR><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">form</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN>
    <P>
    </P>
    <P>Notice the bolded parts.&nbsp; When the page loads, all the boxes are checked.&nbsp; If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.</P>
  • biziclop 2006-08-30 14:42
    Aximilation:
    Oh yes, forget the whole $_REQUEST.....very nice. I've always wanted to create the new and improved version of that. Lol...<br>It's almost as bad as the new link tag seen elsewhere on this site last week...<br>&lt;a onclick="location='http://www.aximilation.com'; return false;" href="#"&gt;The &lt;em&gt;new&lt;/em&gt; link!&lt;/a&gt;<br>(I'm making a t-shirt!)<br>
    <br><br>Resistance is futile.<br>
  • foo 2006-08-30 14:43
    It's so beautiful! I'm crying... no wait... that's blood... FROM MY EYES!<br>
  • maht 2006-08-30 14:43
    the guy *almost* invented Ajax<br>
  • Anon 2006-08-30 14:44
    Anonymous:

    <P>Notice the bolded parts.&nbsp; When the page loads, all the boxes are checked.&nbsp; If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.</P>
    <P>
    </P>
    <P>Wait, I was wrong.&nbsp; That doesn't say "checked" it says "on".&nbsp; This was so stupid I mentally filled in what he <EM>should have been doing</EM> instead of what he actually did.</P>
    <P>&nbsp;</P>
    <P>Wow, that's a lot of work to be so wrong.</P>
  • Tomer Chachamu 2006-08-30 14:50
    Actually, 'value="ON"' does not mean the box is checked. It just means that if it *is* checked, the value to send to the server is "ON".<br><br>Considering that that value presumbly isn't used (since checkedValues.value holds the list of checked checkboxes) you have to wonder why it's there. Just another copy-paste job, I suppose...<br>
  • snoofle 2006-08-30 14:52
    Anonymous:
    Anonymous:

    <P>Notice the bolded parts.&nbsp; When the page loads, all the boxes are checked.&nbsp; If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.</P>
    <P>
    </P>
    <P>Wait, I was wrong.&nbsp; That doesn't say "checked" it says "on".&nbsp; This was so stupid I mentally filled in what he <EM>should have been doing</EM> instead of what he actually did.</P>
    <P>Wow, that's a lot of work to be so wrong.</P>
    <P>
    </P>
    <P>Web-neophyte here - I thought check boxes could only be true/false, or possibly [un]checked. "On" ???</P>
  • ole gustie 2006-08-30 14:53
    Anonymous:
    Alex Papadimoulis:

    <P><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">script</SPAN><SPAN style="COLOR: #ff0000"> type<SPAN style="COLOR: #0000ff">="text/javascript"</SPAN></SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN> <SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">!--</SPAN><SPAN style="COLOR: #000000"><BR><BR>function onCheck(id)<BR>{<BR>&nbsp; checkedValues = document.selecter.checkedValues;<BR>&nbsp; checkedBox = document.selecter["check_"+id];<BR>&nbsp; <BR>&nbsp; if (!checkedBox.checked)<BR>&nbsp;&nbsp;&nbsp; checkedValues.value = <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; eval("checkedValues.value.replace(/" +id + ',' + "/g,'')");<BR>&nbsp; else<BR>&nbsp;&nbsp;&nbsp; <FONT size=4><STRONG>checkedValues.value+=(id+',');</STRONG><BR></FONT>}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>function submit()<BR>{<BR>&nbsp; document.location.href = 'insert.php?chosen=' + <BR>&nbsp;&nbsp;&nbsp;&nbsp; document.selecter.checkedValues.value;<BR>&nbsp; return false;<BR>}<BR><BR><BR>//--</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">script</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><BR><BR><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">form</SPAN><SPAN style="COLOR: #ff0000"> id<SPAN style="COLOR: #0000ff">="selecter"</SPAN> name<SPAN style="COLOR: #0000ff">="selecter"</SPAN></SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN><BR>&nbsp; <SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">input</SPAN><SPAN style="COLOR: #ff0000"> type<SPAN style="COLOR: #0000ff">="hidden"</SPAN> id<SPAN style="COLOR: #0000ff">="checkedValues"</SPAN> name<SPAN style="COLOR: #0000ff">="checkedValues"</SPAN> </SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><BR>&nbsp; <SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">input</SPAN><SPAN style="COLOR: #ff0000"> class<SPAN style="COLOR: #0000ff">="button"</SPAN> type<SPAN style="COLOR: #0000ff">="button"</SPAN> value<SPAN style="COLOR: #0000ff">="Submit"</SPAN> onclick<SPAN style="COLOR: #0000ff">="submit()"</SPAN> </SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><BR><BR>&nbsp; <SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">input</SPAN><SPAN style="COLOR: #ff0000"> id<SPAN style="COLOR: #0000ff">="check_4273844"</SPAN> onclick<SPAN style="COLOR: #0000ff">="onCheck('4273844')"</SPAN> type<SPAN style="COLOR: #0000ff">="checkbox"</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<SPAN style="COLOR: #0000ff">="check_4273844"</SPAN> <STRONG><FONT size=4>value<SPAN style="COLOR: #0000ff">="ON"</SPAN></FONT></STRONG> </SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><BR>&nbsp; ...<BR>&nbsp; <SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">input</SPAN><SPAN style="COLOR: #ff0000"> id<SPAN style="COLOR: #0000ff">="check_4273843"</SPAN> onclick<SPAN style="COLOR: #0000ff">="onCheck('4273843')"</SPAN> type<SPAN style="COLOR: #0000ff">="checkbox"</SPAN><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<SPAN style="COLOR: #0000ff">="check_4273843"</SPAN> <STRONG><FONT size=4>value<SPAN style="COLOR: #0000ff">="ON"</SPAN></FONT></STRONG> </SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><BR>&nbsp; ...<BR>&nbsp; <SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">input</SPAN><SPAN style="COLOR: #ff0000"> id<SPAN style="COLOR: #0000ff">="check_4273842"</SPAN> onclick<SPAN style="COLOR: #0000ff">="onCheck('4273842')"</SPAN> type<SPAN style="COLOR: #0000ff">="checkbox"</SPAN> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<SPAN style="COLOR: #0000ff">="check_4273842"</SPAN> <STRONG><FONT size=4>value<SPAN style="COLOR: #0000ff">="ON"</SPAN></FONT></STRONG> </SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN><BR>&nbsp; ...<BR><SPAN style="COLOR: #0000ff">&lt;/</SPAN><SPAN style="COLOR: #800000">form</SPAN><SPAN style="COLOR: #0000ff">&gt;</SPAN>
    <P>
    </P>
    <P>Notice the bolded parts.&nbsp; When the page loads, all the boxes are checked.&nbsp; If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.</P>
    <P>
    </P>
    <P>&nbsp;</P>
    <P><FONT face=Arial size=2>Huh?&nbsp; value="on" doesn't autocheck a box on the page load.&nbsp; I think you are thinking of</FONT></P>
    <P>&nbsp;<SPAN>&lt;</SPAN><SPAN>input</SPAN><SPAN> id<SPAN>="check_4273842"</SPAN> onclick<SPAN>="onCheck('4273842')"</SPAN> type<SPAN>="checkbox"</SPAN> <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<SPAN>="check_4273842"</SPAN> <STRONG><FONT size=4>checked</FONT></STRONG></SPAN><SPAN>/&gt;<BR><BR><FONT face=Arial size=2>Or am I missing something (trust me, its happened before)?</FONT></SPAN></P>
  • ole gustie 2006-08-30 14:59
    snoofle:
    Anonymous:
    Anonymous:

    <P>Notice the bolded parts.&nbsp; When the page loads, all the boxes are checked.&nbsp; If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.</P>
    <P>
    </P>
    <P>Wait, I was wrong.&nbsp; That doesn't say "checked" it says "on".&nbsp; This was so stupid I mentally filled in what he <EM>should have been doing</EM> instead of what he actually did.</P>
    <P>Wow, that's a lot of work to be so wrong.</P>
    <P>
    </P>
    <P>Web-neophyte here - I thought check boxes could only be true/false, or possibly [un]checked. "On" ???</P>
    <P>
    </P>
    <P>Check boxes pass whatever is in the "value" attribute to the form action page when they are checked.&nbsp; If they are not checked, they pass nothing.&nbsp; If more than one checkboxes have the same name,&nbsp; all that are checked are passed in a single variable as a comma seperated list.&nbsp; Basically, the guy/gal wrote a bunch of crap code to do what standard html forms already do.</P>
  • Tukaro 2006-08-30 15:02
    It burns.<br><br>It burns. So. Much.<br><br>Please. Someone make it stop!<br>
  • snoofle 2006-08-30 15:10
    ole gustie:
    snoofle:
    Anonymous:
    Anonymous:

    <P>Notice the bolded parts.&nbsp; When the page loads, all the boxes are checked.&nbsp; If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.</P>
    <P>
    </P>
    <P>Wait, I was wrong.&nbsp; That doesn't say "checked" it says "on".&nbsp; This was so stupid I mentally filled in what he <EM>should have been doing</EM> instead of what he actually did.</P>
    <P>Wow, that's a lot of work to be so wrong.</P>
    <P>
    </P>
    <P>Web-neophyte here - I thought check boxes could only be true/false, or possibly [un]checked. "On" ???</P>
    <P>
    </P>
    <P>Check boxes pass whatever is in the "value" attribute to the form action page when they are checked.&nbsp; If they are not checked, they pass nothing.&nbsp; If more than one checkboxes have the same name,&nbsp; all that are checked are passed in a single variable as a comma seperated list.&nbsp; Basically, the guy/gal wrote a bunch of crap code to do what standard html forms already do.</P>
    <P>
    </P>
    <P>Thanks - I know just enough about all-things-web to realize how little I know about all-things-web (I tend to stay on the server-side of things - where I know what I'm doing).</P>
  • Marcos 2006-08-30 15:24
    &gt; If more than one checkboxes have the same name,&nbsp; all that are
    checked are passed in a <br>&gt; single variable as a comma seperated list.&nbsp; <br><br>Not true. If more than one checkbox with the same name is checked, then each value is included as a separate name=value pair in the HTTP request.&nbsp; For instance, if the form has a method of GET and the browser uses the old ampersand separator instead of the newfangled semicolon, a form with three checkboxes named "box" checked might take you to this URL:<br><br>http://foo.com/mySpiffyPage.php?box=yup&amp;box=nope&amp;box=is_too<br><br>How that is presented on the server side depends on the language and API being used.&nbsp; I've seen ASP's that seem to indicate that VB in an ASP will give you a comma-separated string, though I don't know how you then deal with commas in an individual value. &nbsp; Most APIs provide a means of getting the list of values as an array;&nbsp; Perl's CGI::param automatically returns an array in list context if there's more than one value, for instance.&nbsp; PHP apparently discards all but the last value unless the name ends with [], which isn't even legal HTML.&nbsp; Of course, there are various add-on solutions to this problem that all involve manually reprocessing the form input...<br><br><br><br><br>
  • Otto 2006-08-30 15:31
    Anonymous:
    Check boxes pass whatever is in the "value"
    attribute to the form action page when they are checked.&nbsp; If they are
    not checked, they pass nothing.&nbsp; If more than one checkboxes have the
    same name,&nbsp; all that are checked are passed in a single variable as a
    comma seperated list.&nbsp; Basically, the guy/gal wrote a bunch of crap
    code to do what standard html forms already do.
    <br>
    <br>
    I knew this didn't sound right, so I tried it. What I got in the URL for a GET request looked like this:<br>
    key=test&amp;key=test2<br>
    <br>
    Now, your language/CGI parser library may change this into something
    nicer like a comma separated list for you, but the data is actually
    sent as multiple key=value pairs, only using the same keys.<br>
    <br>
  • Romeo 2006-08-30 15:36
    Anonymous:
    Anonymous:
    Alex Papadimoulis:

    <p><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(255, 0, 0);"> type<span style="color: rgb(0, 0, 255);">="text/javascript"</span></span><span style="color: rgb(0, 0, 255);">&gt;</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">!--</span><span style="color: rgb(0, 0, 0);"><br><br>function onCheck(id)<br>{<br>&nbsp; checkedValues = document.selecter.checkedValues;<br>&nbsp; checkedBox = document.selecter["check_"+id];<br>&nbsp; <br>&nbsp; if (!checkedBox.checked)<br>&nbsp;&nbsp;&nbsp; checkedValues.value = <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; eval("checkedValues.value.replace(/" +id + ',' + "/g,'')");<br>&nbsp; else<br>&nbsp;&nbsp;&nbsp; <font size="4"><strong>checkedValues.value+=(id+',');</strong><br></font>}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>function submit()<br>{<br>&nbsp; document.location.href = 'insert.php?chosen=' + <br>&nbsp;&nbsp;&nbsp;&nbsp; document.selecter.checkedValues.value;<br>&nbsp; return false;<br>}<br><br><br>//--</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span><br><br><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">form</span><span style="color: rgb(255, 0, 0);"> id<span style="color: rgb(0, 0, 255);">="selecter"</span> name<span style="color: rgb(0, 0, 255);">="selecter"</span></span><span style="color: rgb(0, 0, 255);">&gt;</span><br>&nbsp; <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> type<span style="color: rgb(0, 0, 255);">="hidden"</span> id<span style="color: rgb(0, 0, 255);">="checkedValues"</span> name<span style="color: rgb(0, 0, 255);">="checkedValues"</span> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><br>&nbsp; <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> class<span style="color: rgb(0, 0, 255);">="button"</span> type<span style="color: rgb(0, 0, 255);">="button"</span> value<span style="color: rgb(0, 0, 255);">="Submit"</span> onclick<span style="color: rgb(0, 0, 255);">="submit()"</span> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><br><br>&nbsp; <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> id<span style="color: rgb(0, 0, 255);">="check_4273844"</span> onclick<span style="color: rgb(0, 0, 255);">="onCheck('4273844')"</span> type<span style="color: rgb(0, 0, 255);">="checkbox"</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="color: rgb(0, 0, 255);">="check_4273844"</span> <strong><font size="4">value<span style="color: rgb(0, 0, 255);">="ON"</span></font></strong> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><br>&nbsp; ...<br>&nbsp; <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> id<span style="color: rgb(0, 0, 255);">="check_4273843"</span> onclick<span style="color: rgb(0, 0, 255);">="onCheck('4273843')"</span> type<span style="color: rgb(0, 0, 255);">="checkbox"</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="color: rgb(0, 0, 255);">="check_4273843"</span> <strong><font size="4">value<span style="color: rgb(0, 0, 255);">="ON"</span></font></strong> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><br>&nbsp; ...<br>&nbsp; <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> id<span style="color: rgb(0, 0, 255);">="check_4273842"</span> onclick<span style="color: rgb(0, 0, 255);">="onCheck('4273842')"</span> type<span style="color: rgb(0, 0, 255);">="checkbox"</span> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="color: rgb(0, 0, 255);">="check_4273842"</span> <strong><font size="4">value<span style="color: rgb(0, 0, 255);">="ON"</span></font></strong> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><br>&nbsp; ...<br><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">form</span><span style="color: rgb(0, 0, 255);">&gt;</span>
    </p><p>
    </p>
    <p>Notice the bolded parts.&nbsp; When the page loads, all the boxes are checked.&nbsp; If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.</p>
    <p>
    </p>
    <p>&nbsp;</p>
    <p><font face="Arial" size="2">Huh?&nbsp; value="on" doesn't autocheck a box on the page load.&nbsp; I think you are thinking of</font></p>
    <p>&nbsp;<span>&lt;</span><span>input</span><span> id<span>="check_4273842"</span> onclick<span>="onCheck('4273842')"</span> type<span>="checkbox"</span> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span>="check_4273842"</span> <strong><font size="4">checked</font></strong></span><span>/&gt;<br><br><font face="Arial" size="2">Or am I missing something (trust me, its happened before)?</font></span></p>
    <br><br>Sure you're not missing anything.<br><br>WTF on WTF<br>
  • ole gustie 2006-08-30 15:40
    <P>Thanks for the correction.&nbsp; I guess you learn something new everyday.&nbsp; I am mainly a client app programmer, so my experience is limited to a couple ASP and coldFusion (gross, I know) hobby sites I help my fellow geeks maintain.</P>
    <P>And the answer to your question is that you learn to keep commas out of the indivdual checkbox values pretty quickly.</P>
  • trippyz 2006-08-30 15:45
    >Actually, 'value="ON"' does not mean the box is checked. It just means that if it *is* checked, the value to send to the server is "ON".

    My eyes are checkered, does that mean they are on?
  • qbolec 2006-08-30 15:56
    Alex Papadimoulis:

    <pre>
    function submit()
    {
    document.location.href = 'insert.php?chosen=' +
    document.selecter.checkedValues.value;
    return false;
    }
    </pre>


    I'm afraid of:

    <pre>
    //insert.php
    mysql_query("INSERT INTO MyOrder (ID) VALUES ($chosen)");
    </pre>

  • Volmarias 2006-08-30 16:09
    Good god, I actually tore at my skin with my fingernails when I read this.

    <img src="http://volmari.as/images/head_explode.jpg">
  • cedric 2006-08-30 16:17
    I could imagine why one would want to reconstruct the querystring and bypass the normal form submission. For instance if there is another javascript function attached to the onSubmit event and for some reason you don't want it to run when you click on that button.<br><br>The eval on the string replace is a bit weird. It looks like a workaround for someone who don't know about the RegExp() object (you can't use variables with the // notation). But you don't really need a regular expression in the first place.<br>
  • CodeRage 2006-08-30 16:18
    <font face="Courier New" size="2"><font face="Arial">Just to clarify from the PHP people... Is there some reason you wouldn't just use the following ... like I'd do with a Java/Servlet back-end?&nbsp; Is there some reason building a comma separated string would make things easier in PHP?&nbsp; I would just use the HttpServletRequest to give me an array of the "chosen" parameters...</font><br><br>&lt;form id="selecter" name="selecter" action="insert.php"&gt;<br>&nbsp; &lt;input class="button" type="submit" value="Submit" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273844" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273843" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273842" /&gt;<br>&nbsp; ...<br>&lt;/form&gt;<br><br></font>
  • UTU 2006-08-30 16:19
    Anonymous:
    PHP apparently discards all but the last value unless the name ends with [], which isn't even legal HTML.
    <br><br>Umm.. how so? If my memory serves me correctly, "name"-attribute of input-elements is of type CDATA, which means "a sequence of characters from
    the document character set"... so ending a name with [] is just about as allowed in HTML as ... well, just about anything :)<br>
  • smbell 2006-08-30 16:21
    Volmarias:
    Good god, I actually tore at my skin with my fingernails when I read this.

    <img src="http://volmari.as/images/head_explode.jpg">
    <br><br>Oooh, I need to get a webcam at my desk too.<br>
  • Kelsey 2006-08-30 16:21
    Young Padewan - checkboxes have three states - true, false, and FileNotFound.<br>"On" is indeed the real WTF here.<br>
  • WWWWolf 2006-08-30 16:23
    qbolec:
    Alex Papadimoulis:

    <pre>
    function submit()
    {
    document.location.href = 'insert.php?chosen=' +
    document.selecter.checkedValues.value;
    return false;
    }
    </pre>


    I'm afraid of:

    <pre>
    //insert.php
    mysql_query("INSERT INTO MyOrder (ID) VALUES ($chosen)");
    </pre>
    <br><br>Yeah, let's combine a great big web app design flaw with a PHP-specific design flaw: SQL injection annnnnd register_globals... =)<br>
  • Licky Lindsay 2006-08-30 16:26
    ole gustie:
    I am mainly a client app programmer, so my
    experience is limited to a couple ASP and coldFusion (gross, I know)
    hobby sites I help my fellow geeks maintain.
    <br>
    <br>
    You would be very surprised (well, no, you wouldn't really) how many
    people who work with one of those languages every day, and are paid to
    do so, actually think that the browser sends a comma-separated list.<br>
    <br>
    captcha: whiskey<br>
  • UTU 2006-08-30 16:26
    CodeRage:
    <font face="Courier New" size="2"><font face="Arial">Just to clarify from the PHP people... Is there some reason you wouldn't just use the following ... like I'd do with a Java/Servlet back-end?&nbsp; Is there some reason building a comma separated string would make things easier in PHP?&nbsp; I would just use the HttpServletRequest to give me an array of the "chosen" parameters...</font><br><br>&lt;form id="selecter" name="selecter" action="insert.php"&gt;<br>&nbsp; &lt;input class="button" type="submit" value="Submit" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273844" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273843" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273842" /&gt;<br>&nbsp; ...<br>&lt;/form&gt;<br><br></font>
    <br><br>Yes, there is a reason. See http://fi2.php.net/manual/en/faq.html.php#faq.html.arrays for explanation. However, if your example were like 'name="chosen[]"', there would be no problem; we'd have array $_GET["chosen"] to use :)<br>
  • Licky Lindsay 2006-08-30 16:32
    Anonymous:
    Anonymous:
    PHP apparently discards
    all but the last value unless the name ends with [], which isn't even
    legal HTML.
    <br><br>Umm.. how so? If my memory serves me
    correctly, "name"-attribute of input-elements is of type CDATA, which
    means "a sequence of characters from
    the document character set"... so ending a name with [] is just about
    as allowed in HTML as ... well, just about anything :)<br>
    <br>
    <br>
    PHP isn't the only "framework" that uses that kind of thing either. Struts, for instance, uses the hell out of it.<br>
    <br>
    Captcha: error<br>
  • Ann Coulter 2006-08-30 16:35
    Anonymous:
    Anonymous:
    Alex Papadimoulis:

    <p><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(255, 0, 0);"> type<span style="color: rgb(0, 0, 255);">="text/javascript"</span></span><span style="color: rgb(0, 0, 255);">&gt;</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">!--</span><span style="color: rgb(0, 0, 0);"><br><br>function onCheck(id)<br>{<br>&nbsp; checkedValues = document.selecter.checkedValues;<br>&nbsp; checkedBox = document.selecter["check_"+id];<br>&nbsp; <br>&nbsp; if (!checkedBox.checked)<br>&nbsp;&nbsp;&nbsp; checkedValues.value = <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; eval("checkedValues.value.replace(/" +id + ',' + "/g,'')");<br>&nbsp; else<br>&nbsp;&nbsp;&nbsp; <font size="4"><strong>checkedValues.value+=(id+',');</strong><br></font>}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>function submit()<br>{<br>&nbsp; document.location.href = 'insert.php?chosen=' + <br>&nbsp;&nbsp;&nbsp;&nbsp; document.selecter.checkedValues.value;<br>&nbsp; return false;<br>}<br><br><br>//--</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">script</span><span style="color: rgb(0, 0, 255);">&gt;</span><br><br><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">form</span><span style="color: rgb(255, 0, 0);"> id<span style="color: rgb(0, 0, 255);">="selecter"</span> name<span style="color: rgb(0, 0, 255);">="selecter"</span></span><span style="color: rgb(0, 0, 255);">&gt;</span><br>&nbsp; <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> type<span style="color: rgb(0, 0, 255);">="hidden"</span> id<span style="color: rgb(0, 0, 255);">="checkedValues"</span> name<span style="color: rgb(0, 0, 255);">="checkedValues"</span> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><br>&nbsp; <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> class<span style="color: rgb(0, 0, 255);">="button"</span> type<span style="color: rgb(0, 0, 255);">="button"</span> value<span style="color: rgb(0, 0, 255);">="Submit"</span> onclick<span style="color: rgb(0, 0, 255);">="submit()"</span> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><br><br>&nbsp; <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> id<span style="color: rgb(0, 0, 255);">="check_4273844"</span> onclick<span style="color: rgb(0, 0, 255);">="onCheck('4273844')"</span> type<span style="color: rgb(0, 0, 255);">="checkbox"</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="color: rgb(0, 0, 255);">="check_4273844"</span> <strong><font size="4">value<span style="color: rgb(0, 0, 255);">="ON"</span></font></strong> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><br>&nbsp; ...<br>&nbsp; <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> id<span style="color: rgb(0, 0, 255);">="check_4273843"</span> onclick<span style="color: rgb(0, 0, 255);">="onCheck('4273843')"</span> type<span style="color: rgb(0, 0, 255);">="checkbox"</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="color: rgb(0, 0, 255);">="check_4273843"</span> <strong><font size="4">value<span style="color: rgb(0, 0, 255);">="ON"</span></font></strong> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><br>&nbsp; ...<br>&nbsp; <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span><span style="color: rgb(255, 0, 0);"> id<span style="color: rgb(0, 0, 255);">="check_4273842"</span> onclick<span style="color: rgb(0, 0, 255);">="onCheck('4273842')"</span> type<span style="color: rgb(0, 0, 255);">="checkbox"</span> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span style="color: rgb(0, 0, 255);">="check_4273842"</span> <strong><font size="4">value<span style="color: rgb(0, 0, 255);">="ON"</span></font></strong> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><br>&nbsp; ...<br><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">form</span><span style="color: rgb(0, 0, 255);">&gt;</span>
    </p><p>
    </p>
    <p>Notice the bolded parts.&nbsp; When the page loads, all the boxes are checked.&nbsp; If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.</p>
    <p>
    </p>
    <p>&nbsp;</p>
    <p><font face="Arial" size="2">Huh?&nbsp; value="on" doesn't autocheck a box on the page load.&nbsp; I think you are thinking of</font></p>
    <p>&nbsp;<span>&lt;</span><span>input</span><span> id<span>="check_4273842"</span> onclick<span>="onCheck('4273842')"</span> type<span>="checkbox"</span> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span>="check_4273842"</span> <strong><font size="4">checked</font></strong></span><span>/&gt;<br><br><font face="Arial" size="2">Or am I missing something (trust me, its happened before)?</font></span></p>
    <br><br>Well, if you're going to use xhtml you should make it <br><br><span>&lt;</span><span>input</span><span> id<span>="check_4273842"</span> onclick<span>="onCheck('4273842')"</span> type<span>="checkbox"</span> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name<span>="check_4273842"</span> <strong><font size="4">checked</font></strong></span><span><b>="</b></span><span><strong><font size="4">checked</font></strong></span><span></span><span><b>"</b>/&gt;</span><br>
  • WHO WANTS TO KNOW? 2006-08-30 16:36
    <P>Actually, PHP even has a design flaw that makes this CHILDS PLAY!&nbsp; Then again, the new PROPER way isn't much harder.&nbsp; PHP was built from the ground up to work with this stuff.</P>
    <P>Steve</P>
  • ammoQ 2006-08-30 16:38
    Anonymous:
    <br>Yes, there is a reason. See http://fi2.php.net/manual/en/faq.html.php#faq.html.arrays for explanation. However, if your example were like 'name="chosen[]"', there would be no problem; we'd have array $_GET["chosen"] to use :)<br>
    <br><br>Hard to believe. How can a programming language especially made for web programming require such client-visible workarounds to accomplish such basic tasks? Even Oracle's Web toolkit (web programming in PL/SQL, introduced around '99) does it better.<br>
  • ammoQ 2006-08-30 16:40
    Anonymous:
    <br>
    PHP isn't the only "framework" that uses that kind of thing either. Struts, for instance, uses the hell out of it.<br>
    <br>Maybe, but struts has a higher level of abstraction.<br>
  • Rich 2006-08-30 16:51
    PHP will only accept arrays of inputs if the input is named with a [] suffix. This is a pet peeve of mine, I feel that a proper server side web scripting language *should* be able to handle whatever form data is sent at it sanely.<br><br>If I remember ASP correctly (it's been a while), if you read the input directly, you get a comma separated list but you can also read the input as an array [Don't remember how but it's fairly simple]. I think the comma separated list is an awful holdover from htx/idc of the original IIS (Makes me feel queasy just thinking about it).<br><br>Rich<br>
  • savar 2006-08-30 16:52
    ammoQ:
    <br><br>Hard to believe. How can a programming language especially made for web programming require such client-visible workarounds to accomplish such basic tasks? Even Oracle's Web toolkit (web programming in PL/SQL, introduced around '99) does it better.<br>
    <br><br>It's not a work-around, it's just how things are done. PHP isn't an amazingly clever language, but what's wrong with using [] to return an array? It's no more client-visible than using the same name without [] for each element.<br>
  • NZ'er 2006-08-30 16:58
    Anonymous:
    CodeRage:
    <font face="Courier New" size="2"><font face="Arial">Just to clarify from the PHP people... Is there some reason you wouldn't just use the following ... like I'd do with a Java/Servlet back-end?&nbsp; Is there some reason building a comma separated string would make things easier in PHP?&nbsp; I would just use the HttpServletRequest to give me an array of the "chosen" parameters...</font><br><br>&lt;form id="selecter" name="selecter" action="insert.php"&gt;<br>&nbsp; &lt;input class="button" type="submit" value="Submit" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273844" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273843" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273842" /&gt;<br>&nbsp; ...<br>&lt;/form&gt;<br><br></font>
    <br><br>Yes, there is a reason. See http://fi2.php.net/manual/en/faq.html.php#faq.html.arrays for explanation. However, if your example were like 'name="chosen[]"', there would be no problem; we'd have array $_GET["chosen"] to use :)<br>
    <br><br>Cheers for this!&nbsp; I am relitivly new to PHP programming and was trying to do somthing similar (trying to get PHP to accept an array of inputs, not the horrible javascript thing) and ran out of energy to Google it and find out. So this just saved me some time.&nbsp; I have done similar things in perl and PL/SQL and both seem simpler to me but I guess it is just a quirk of the language.<br><br>
  • Rich 2006-08-30 17:00
    ammoQ:
    <br>Hard to believe. How can a programming language especially made for web programming require such client-visible workarounds to accomplish such basic tasks? Even Oracle's Web toolkit (web programming in PL/SQL, introduced around '99) does it better.<br>
    <br><br>Not that I want to be seen to be defending PHP particularly (I use it a fair bit but I am a sysadmin, no longer a full-time programmer) but it must be remembered that PHP originated as a very simple language to make designing simple homepages quick and relatively painless. Crap such as [] is pretty easy to understand in that context, much like the magic quotes and other braindead stuff.<br><br>That said, it should have deprecated by now and been replaced with something saner. I did ask about it recently and was told that there were technical reasons or ot was "too difficult" to do things any other way (which I immediately rebutted of course). I took that to mean that the PHP developers had not yet had the appropriate epiphany. I am sure they will. But in the meantime, the insanity remains.<br><br>Rich<br>
  • ammoQ 2006-08-30 17:04
    savar:
    ammoQ:
    <br><br>Hard to believe. How can a programming language especially made for web programming require such client-visible workarounds to accomplish such basic tasks? Even Oracle's Web toolkit (web programming in PL/SQL, introduced around '99) does it better.<br>
    <br><br>It's not a work-around, it's just how things are done. PHP isn't an amazingly clever language, but what's wrong with using [] to return an array? It's no more client-visible than using the same name without [] for each element.<br>
    <br><br>What's wrong with that? Well, it means PHP can be unable to process (perfectly legal from a HTTP point of view) input coming from another page (possibly even another server) that does not know or care about that.<br>It means implementation details inevitably leak through to a tier where they should be invisible.<br>
  • CodeRage 2006-08-30 17:06
    Anonymous:
    Anonymous:
    CodeRage:
    <font face="Courier New" size="2"><font face="Arial">Just to clarify from the PHP people... Is there some reason you wouldn't just use the following ... like I'd do with a Java/Servlet back-end?&nbsp; Is there some reason building a comma separated string would make things easier in PHP?&nbsp; I would just use the HttpServletRequest to give me an array of the "chosen" parameters...</font><br><br>&lt;form id="selecter" name="selecter" action="insert.php"&gt;<br>&nbsp; &lt;input class="button" type="submit" value="Submit" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273844" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273843" /&gt;<br>&nbsp; ...<br>&nbsp; &lt;input type="checkbox" name="chosen" value="4273842" /&gt;<br>&nbsp; ...<br>&lt;/form&gt;<br><br></font>
    <br><br>Yes, there is a reason. See http://fi2.php.net/manual/en/faq.html.php#faq.html.arrays for explanation. However, if your example were like 'name="chosen[]"', there would be no problem; we'd have array $_GET["chosen"] to use :)<br>
    <br><br>Cheers for this!&nbsp; I am relitivly new to PHP programming and was trying to do somthing similar (trying to get PHP to accept an array of inputs, not the horrible javascript thing) and ran out of energy to Google it and find out. So this just saved me some time.&nbsp; I have done similar things in perl and PL/SQL and both seem simpler to me but I guess it is just a quirk of the language.<br><br>
    <br>Yeeesh, I'm glad I don't use PHP.&nbsp; How hard is it to parse the key/value pairs in the http post or get, and then build an array for any key that has more than one occurrence...Anyway, thanks to all for clarifying this to me.<br>
  • ammoQ 2006-08-30 17:09
    Anonymous:
    <br>Not that I want to be seen to be defending PHP particularly (I use it a fair bit but I am a sysadmin, no longer a full-time programmer) but it must be remembered that PHP originated as a very simple language to make designing simple homepages quick and relatively painless. Crap such as [] is pretty easy to understand in that context, much like the magic quotes and other braindead stuff.<br><br>That said, it should have deprecated by now and been replaced with something saner. I did ask about it recently and was told that there were technical reasons or ot was "too difficult" to do things any other way (which I immediately rebutted of course). I took that to mean that the PHP developers had not yet had the appropriate epiphany. I am sure they will. But in the meantime, the insanity remains.<br>
    <br><br>That's why I don't like PHP. It started as a quick hack for simple things but the shortcomings are so deep within its core that it will never be able to become a really good language.<br>
  • ammoQ 2006-08-30 17:13
    CodeRage:
    <br>Yeeesh, I'm glad I don't use PHP.&nbsp; How hard is it to parse the key/value pairs in the http post or get, and then build an array for any key that has more than one occurance...Anyway, thanks to all for clarifying this to me.<br>
    <br><br>The problem is that if there is excactly one occurrence, it might be just by pure luck, because the user checked one of several checkboxes. The program expects an array and crashes; unfortunately, in PHP, to make things simple, the program cannot tell the HTTP parser if it expects a single occurrence (therefore a simple variable) or an array.<br>
  • qbolec 2006-08-30 17:14
    WWWWolf:
    qbolec:
    Alex Papadimoulis:
    <PRE>
    function submit()
    {
    document.location.href = 'insert.php?chosen=' +
    document.selecter.checkedValues.value;
    return false;
    }
    </PRE>
    I'm afraid of: <PRE>
    //insert.php
    mysql_query("INSERT INTO MyOrder (ID) VALUES ($chosen)");
    </PRE>
    <P>
    <BR><BR>Yeah, let's combine a great big web app design flaw with a PHP-specific design flaw: SQL injection annnnnd register_globals... =)<BR>
    </P>
    <P>Yeah, I'm almost 100% sure he's using register_globals, otherwise he would probably came up what's $_REQUSET for...</P>
    <P>As WTF as it was it perfectly matches the design of <A href="http://www.realestate.com.au/cgi-bin/rsearch?a=sf&amp;s=qld&amp;t=ren&amp;snf=rbs">http://www.realestate.com.au/cgi-bin/rsearch?a=sf&amp;s=qld&amp;t=ren&amp;snf=rbs</A>&nbsp; (take a while to play with the select box and watch the textbox)</P>
    <P>..and I was asked to make a new page with similar in feel&amp;look to this one - I told them that this multi-selectbox 'rescripting' is retarded and counter-intuitive to anyone that handled at least one Window's app before. They told me, that this exactly meet future administrators of the new website description... (retarded and never used Windows apps??) and I was told to cooperate and just copy the javascript from this site ... (well I obviously took a look at that script, but no, I didn't copy it...)</P>
    <P>To calm my guilty conscience, I made sure that this script is easy to delete from the future release, when the new hax0rz, capable of handling selectboxes will be born to take over the administration of my site.</P>
    <P>(And to make it perfectly clear, the <A href="http://www.realstate.com.au">www.realstate.com.au</A> had nothing to do with my job, it was just a reference website, to help explain to me how should I implement the new site for the contractor)</P>
  • Anaerin 2006-08-30 17:21
    I deal with ASP a lot. Essentially all parameters passed in are "StringList"s. The default return value of a StringList is all elements concatenated with commas.<br><br>So, for the URL: thing.asp?test=1&amp;test=2<br><br>Request.QueryString("Test")="1,2"<br><br>However, you can also do:<br><br>Request.QueryString("Test").Count=2<br>Request.QueryString("Test").Value(0)="1"<br>Request.QueryString("Test").Value(1)="2"<br><br>(Which can be shortened down to Request.QueryString("Test")(0) as "Value" is the default parameter).<br><br>So there's no problems with commas, if you use the objects the way they're meant to be used.<br>
  • viraptor 2006-08-30 17:29
    ammoQ:
    <br>The problem is that if there is excactly one occurrence, it might be just by pure luck, because the user checked one of several checkboxes. The program expects an array and crashes; unfortunately, in PHP, to make things simple, the program cannot tell the HTTP parser if it expects a single occurrence (therefore a simple variable) or an array.<br>
    <br>OMG! Is it that hard to do: (ok - this is WTF - php request processing in php):<br><blockquote>foreach($req as $key =&gt; $val) {<br>&nbsp;&nbsp;&nbsp; if(!array_key_exists($key, $_GET))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; $_GET[$key]=$val;<br>&nbsp;&nbsp;&nbsp; else {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; if(is_array($_GET[$key]))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; $_GET[$key][]=$val;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; else {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; $tmp=$_GET[$key];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; $_GET[$key]=array($tmp, $val);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>}<br></blockquote>It's not a rocket science people...<br>Sorry if there's something wrong with code - haven't used php for a while.<br>
  • Rich 2006-08-30 17:30
    ammoQ:
    <br>The problem is that if there is excactly one occurrence, it might be just by pure luck, because the user checked one of several checkboxes. The program expects an array and crashes; unfortunately, in PHP, to make things simple, the program cannot tell the HTTP parser if it expects a single occurrence (therefore a simple variable) or an array.<br>
    <br><br>Simple, have $_REQUEST, $_POST and $_GET that work the normal way and have $_REQUEST_ARRAYS, [etc] that return all request values as arrays (whether multi-valued or not). Or have a function that looks into the GET or POST data and works an array if you'd rather do it on the fly than take the processing hit up-front (it's possible to do this yourself but it should be a language feature).<br><br>Point is that client usage shouldn't be arbitrarily limited by the server (in something with a featureset like PHP has)<br><br>Rich<br>
  • ammoQ 2006-08-30 17:42
    viraptor:
    ammoQ:
    <br>The problem is that if there is excactly one occurrence, it might be just by pure luck, because the user checked one of several checkboxes. The program expects an array and crashes; unfortunately, in PHP, to make things simple, the program cannot tell the HTTP parser if it expects a single occurrence (therefore a simple variable) or an array.<br>
    <br>OMG! Is it that hard to do: (ok - this is WTF - php request processing in php):<br><blockquote>foreach($req as $key =&gt; $val) {<br>&nbsp;&nbsp;&nbsp; if(!array_key_exists($key, $_GET))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; $_GET[$key]=$val;<br>&nbsp;&nbsp;&nbsp; else {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; if(is_array($_GET[$key]))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; $_GET[$key][]=$val;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; else {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; $tmp=$_GET[$key];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; $_GET[$key]=array($tmp, $val);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>}<br></blockquote>It's not a rocket science people...<br>Sorry if there's something wrong with code - haven't used php for a while.<br>
    <br>So the client program has to check the type of $_GET[$key] to see if it gets an array or a simple value this time? I think this is exactly the problem the PHP guys wanted to avoid. Because even if there are 10 equally-named checkboxes, $_GET[$key] would be a simple value if the user has checked only one of them. Or it would not exist at all if none were checked.<br>
  • ammoQ 2006-08-30 17:46
    Anonymous:
    <br>Simple, have $_REQUEST, $_POST and $_GET that work the normal way and have $_REQUEST_ARRAYS, [etc] that return all request values as arrays (whether multi-valued or not). Or have a function that looks into the GET or POST data and works an array if you'd rather do it on the fly than take the processing hit up-front (it's possible to do this yourself but it should be a language feature).<br>
    <br>Yes, that would be the way to go, but it's not compatible with existing programs (register_globals anyone?). And I guess it's against their philosophy. I think they rather keep the program simple and taint the HTML code instead.<br>
    <br>Point is that client usage shouldn't be arbitrarily limited by the server (in something with a featureset like PHP has)<br>
    <br>Couldn't aggree more. Read my "That's why I don't like PHP" post.<br>
  • .NET Developer 2006-08-30 17:47
    No Idea.......
  • viraptor 2006-08-30 17:50
    ammoQ:
    <br>So the client program has to check the type of $_GET[$key] to see if it gets an array or a simple value this time? I think this is exactly the problem the PHP guys wanted to avoid. Because even if there are 10 equally-named checkboxes, $_GET[$key] would be a simple value if the user has checked only one of them. Or it would not exist at all if none were checked.<br>
    <br>Basicaly yes. However, if you use name="arr[]", you still have to check if that array exists. If nothing is there, then there is no $_GET[arr]. If you play defensive, you should also check if is_array($_GET[arr]) anyway. Not checking it and expecting it to be a value, can give you "array", or null for example - and you don't want that to happen.<br>So if you check it anyway - you can as well add this one else case, where it's a single string.<br>
  • AI0867 2006-08-30 18:12
    Anonymous:
    Anonymous:
    Anonymous:
    PHP apparently discards
    all but the last value unless the name ends with [], which isn't even
    legal HTML.
    <br><br>Umm.. how so? If my memory serves me
    correctly, "name"-attribute of input-elements is of type CDATA, which
    means "a sequence of characters from
    the document character set"... so ending a name with [] is just about
    as allowed in HTML as ... well, just about anything :)<br>
    <br>
    <br>
    PHP isn't the only "framework" that uses that kind of thing either. Struts, for instance, uses the hell out of it.<br>
    <br>
    Captcha: error<br>
    <br>actually, i've seen input tags with the names login[username] and login[password], yay for pre-grouping the data.<br>
  • qbolec 2006-08-30 18:12
    <P>Is it just me, or naming all check-boxes "chosen" (or in general in with the same name) is a little bit counter-intuitive? I prefer to think, that check-boxes means items that you want to or don't want to choose, so each of them is separate thing, so I usually name them "choice_0",...,"choice_100", so then you can just perform in&nbsp; PHP simple scan </P><PRE>foreach($_REQUEST as $key)if( startswith($key,"choice_")){do something;}</PRE>or <PRE>for($id=100;$id--;)if(isset($_REQUEST["choice_$id"])){do something;}</PRE>...ok, maybe it's not so simple as it could be with <PRE>foreach($_REQUEST['choice'] as $id){do something;}</PRE>, but at least I know what I'm doing...and the PHP engine knows what's going on...I don't like (or maybe : I do not get) the idea of server deciding whether the variable should be an array or not depending on the number of submitted infos...I also think, that the way to distinguish this two different cases by adding "[]" at the end of the variable is very elegant and concrete.
  • qbolec 2006-08-30 18:27
    <P>
    AI0867:
    <BR>actually, i've seen input tags with the names login[username] and login[password], yay for pre-grouping the data.<BR>
    </P>
    <P>..and I would try to submit handcrafted form with &lt;input name=login[isadmin]&nbsp;value=yep&gt; just to make sure the site is worth of&nbsp;seeing my password...</P>
  • Arancaytar 2006-08-30 18:48
    Hm... so if I got that right, the author of that Javascript didn't trust HTML forms, and instead wrote his own submit-function? Brillant.<br><br>--<br><br>Oh, and the description of that Developmestuction sounds uncomfortably similar to what my predecessor left me. I've started using some of the apparently less intuitive approaches with new web apps (such as versioning, and separate locations for testing and production), but my boss already complained that the system was far too complex, and wouldn't it just be enough to rename the file to "index.php.old", "index.php.old.1" etc. whenever I changed it?<br><br><br>
  • Arancaytar 2006-08-30 18:56
    Oh, I just noticed that the checkboxes will be sent as a comma-separated list this way. Nifty but... why the heck would someone do that? I've made a form like this before and there is absolutely NO difficulty with parsing those parameters in a normal way on the PHP backend, and elegantly.<br><br>The sort of people who think otherwise are responsible for PHP enjoying a reputation that ranks it just above VBscript and just below COBOL.<br>
  • mratzloff 2006-08-30 19:01
    CodeRage:
    Yeeesh, I'm glad I don't use PHP.
    LOL, every thread...
  • mratzloff 2006-08-30 19:15
    The debate about implementation is just a matter of degree.&nbsp; The fact
    that you have a name on an input item reveals something (however small)
    about server-side implementation; otherwise, everything would be static
    or done with ID tags and JavaScript.&nbsp; Adding brackets a la [] to the
    end doesn't reveal any more than having a list of identically-named
    checkboxes, and ensures that those values will always be submitted in
    an array (instead of having to check for a single value).&nbsp; It's an
    extremely minor issue at best, and only particularly relevant to people
    new to the language.<br><br>One possible way to do this is to
    not believe the values submitted but simply query the database,
    retrieve the possible values, then check the submitted data against the
    database IDs.&nbsp; That way people can't submit their own IDs (for
    instance, if there are hidden options).&nbsp; Then it makes no difference
    whether it's chosen_1234 or chosen[1234].
  • woah! 2006-08-30 20:27
    <P>
    CodeRage:
    <BR>And all this for something the browser does for you when it posts the form, had the developer been 1337 enough to give all the checkboxes the same name, with each value being the id.<BR>
    </P>
    <P>Not many people can figure this out.</P>
    <P>Similarly WTFish, in college I had a coworker at a coop job who wrote javascript to submit forms.</P>
    <P>I sat down with him to review a bug, and he was baffled when I fixed it by deleting all the javascript.</P>
    <P>Woah!</P>
  • elitheeli 2006-08-30 22:59
    viraptor:
    ammoQ:
    <br>The problem is that if there is excactly one occurrence, it might be just by pure luck, because the user checked one of several checkboxes. The program expects an array and crashes; unfortunately, in PHP, to make things simple, the program cannot tell the HTTP parser if it expects a single occurrence (therefore a simple variable) or an array.<br>
    <br>OMG! Is it that hard to do: (ok - this is WTF - php request processing in php):<br><blockquote>foreach($req as $key =&gt; $val) {<br>&nbsp;&nbsp;&nbsp; if(!array_key_exists($key, $_GET))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; $_GET[$key]=$val;<br>&nbsp;&nbsp;&nbsp; else {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; if(is_array($_GET[$key]))<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; $_GET[$key][]=$val;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; else {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; $tmp=$_GET[$key];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; $_GET[$key]=array($tmp, $val);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>}<br></blockquote>It's not a rocket science people...<br>Sorry if there's something wrong with code - haven't used php for a while.<br>
    <br><br>Or... just design your websites so that all the form things have different names... how hard is that?<br>
  • powerlord 2006-08-30 23:32
    Anonymous:
    Anonymous:
    PHP apparently discards all but the last value unless the name ends with [], which isn't even legal HTML.
    <br><br>Umm.. how so? If my memory serves me correctly, "name"-attribute of input-elements is of type CDATA, which means "a sequence of characters from
    the document character set"... so ending a name with [] is just about as allowed in HTML as ... well, just about anything :)<br>


    I've always been confused by that. Most tags use a CDATA for name, yet there is a defined NAME type:

    ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
  • Anonymous 2006-08-31 01:54
    Anonymous:
    <p>The story around it&nbsp;is differenct, or&nbsp;this could be&nbsp;jscript from the place I at now as an on-site contractor!<br></p><p>
    </p><br>Didn't you read the post? The place you're at now obviously bought this code on ebay from the same guy the guy in the post bought it from. Duh!<br>
  • Wombat 2006-08-31 04:33
    Anonymous:

    <P>Dare I say "Javascript has the best WTF's" ?</P>
    <P>
    </P>
    <P>Somehow it often does :-)</P>
    <P>I had something of&nbsp;a WTF from Javascript yesterday, but I'm going to blame Javascript rather than myself for it.&nbsp; But I might well be to blame due to my lack of experience with Javascript due to the fact that I avoid it whenever possible.&nbsp; Yesterday, I was creating a Date object and populating it with data from a form.&nbsp; Below is a simplified version of what I did:</P>

    var date = new Date();<BR>
    date.setYear(2000);<BR>
    date.setMonth(1); // 1 for February, since it's zero-based<BR>
    date.setDate(10);<BR>

    <P>Whenever I set it to February, the outcome would magically be March.&nbsp; It took a good few minutes of confusion before I figured out what was happening.&nbsp; The Date contructor was initialising the date to "now" (i.e. yesterday which was 30 August 2006), which is fine because I'm just going to overwrite it anyway.&nbsp; I set the year to 2000, which was fine.&nbsp; Then I set the month to February.&nbsp; But because the day field was already initialised to 30 by the constructor, Javascript thought I was clearly stupid for wanting the 30th of February and changed it to 2nd of March for me behind my back.&nbsp; Then I set the day to 10, which overwrote half of Javascript's automagic befuddling.&nbsp; This left it looking like the only thing that had happened was that Javascript was somehow allergic to February.&nbsp; Of course the potential for this to happen will only happen on the last few days of the month.</P>
    <P>I fixed it with a big table of carefully worked out cases for when to decrement the month after this had happened.&nbsp; No I didn't because that would have been a real WTF.&nbsp; I read the docs and realised I should just do:</P>

    var Date = new Date(2000,1,10);
  • Thomas 2006-08-31 05:04
    <P>
    Anonymous:
    As javascript in itself was designed with good intentions,
    </P>
    <P>Well, as we all know the road to hell is paved with good intentions ...</P>
  • TMLC 2006-08-31 05:23
    <P>One day, someone will implement a date object that makes sence.<BR><BR>Well, ok, maybe not, but the hope keeps me going.</P>
  • NoTime 2006-08-31 05:58
    powerlord:
    I've always been confused by that. Most tags use a CDATA for name,
    <br>That's because that is how it is defined in the HTML DTD.<br>
    powerlord:
    yet there is a defined NAME type:
    <br>HTML != DTD, so a priori there's no reason to assume that an HTML name is the same thing as a DTD name.<br>
  • blair 2006-08-31 07:05
    <P><FONT style="BACKGROUND-COLOR: #bfc6d2">No one noticed that the Javascript is commented away? ...</FONT></P>
  • abc 2006-08-31 07:38
    <P>
    ammoQ:
    CodeRage:
    <BR>Yeeesh, I'm glad I don't use PHP.&nbsp; How hard is it to parse the key/value pairs in the http post or get, and then build an array for any key that has more than one occurance...Anyway, thanks to all for clarifying this to me.<BR>
    <BR><BR>The problem is that if there is excactly one occurrence, it might be just by pure luck, because the user checked one of several checkboxes. The program expects an array and crashes; unfortunately, in PHP, to make things simple, the program cannot tell the HTTP parser if it expects a single occurrence (therefore a simple variable) or an array.<BR>
    If the name of the input has [] suffix, it will always be an array, even if only one indice. therefore:</P>
    <P>
    &lt;input type="checkbox" value="123" name="box[]" /&gt;</P>
    
    <P>...</P>
    <P>&lt;input type="checkbox" value="456" name="box[]" /&gt;
    </P>
    <P>can always be referenced as:</P>
    <P>
    &lt;?php</P>
    
    <P>if (!empty($_GET['array'])) {</P>
    <P>&nbsp;&nbsp;&nbsp; foreach ($_GET['array'] as $array) {</P>
    <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //do something with $array</P>
    <P>&nbsp;&nbsp;&nbsp; }</P>
    <P>} else {</P>
    <P>&nbsp;&nbsp;&nbsp; //no checkboxes selected.</P>
    <P>}</P>
    <P>?&gt;
    </P>
  • GeekMessage 2006-08-31 07:40
    <P>
    Alex Papadimoulis:
    And the previous programmer actually got "in trouble" for trying to sell this proprietary software on eBay.
    </P>
    <P>Won't <STRONG>Andreas</STRONG> get "in trouble" for trying to post this proprietary software on The Daily WTF?</P>
  • abc 2006-08-31 07:43
    <P>Well.. that didn't work..</P>
    <P>&nbsp;</P>
    <P>
    </P>
    <P>&lt;input type="checkbox" value="123" name="box[]" /&gt;</P>
    <P>...</P>
    <P>&lt;input type="checkbox" value="456" name="box[]" /&gt;</P>
    <P>can always be referenced as:</P>
    <P>&lt;?php</P>
    <P>if (!empty($_GET['array'])) {</P>
    <P>&nbsp;&nbsp;&nbsp; foreach ($_GET['array'] as $array) {</P>
    <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //do something with $array</P>
    <P>&nbsp;&nbsp;&nbsp; }</P>
    <P>} else {</P>
    <P>&nbsp;&nbsp;&nbsp; //no checkboxes selected.</P>
    <P>}</P>
    <P>?&gt;
    </P>
  • ammoQ 2006-08-31 07:48
    Anonymous:
    <p>Well.. that didn't work..</p>
    <p>&nbsp;</p>
    <p>
    </p>
    <p>&lt;input type="checkbox" value="123" name="box[]" /&gt;</p>
    <p>...</p>
    <p>&lt;input type="checkbox" value="456" name="box[]" /&gt;</p>
    <p>can always be referenced as:</p>
    <p>&lt;?php</p>
    <p>if (!empty($_GET['array'])) {</p>
    <p>&nbsp;&nbsp;&nbsp; foreach ($_GET['array'] as $array) {</p>
    <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //do something with $array</p>
    <p>&nbsp;&nbsp;&nbsp; }</p>
    <p>} else {</p>
    <p>&nbsp;&nbsp;&nbsp; //no checkboxes selected.</p>
    <p>}</p>
    <p>?&gt;
    </p>
    <br><br>wrong names... box&lt;-&gt;array<br>
  • abc 2006-08-31 07:55
    go me.. perhaps I'm the real wtf?
  • SnapShot 2006-08-31 08:08
    How do you pronounce "TTWTASO"?&nbsp; It's a great design pattern in need of a better acronym.&nbsp; I can't wait to start my next project and walk up to the current developers and say: Hi guys I was looking over the code and I got to say this was an excellent use of the TTWTASO design pattern.<br>
  • ParkinT 2006-08-31 08:19
    <P>Check and double-check.</P>
    <P>If this had been in VBScript it wouldn't be a WTF!!<BR></P>
  • ParkinT 2006-08-31 08:22
    Anonymous:

    <P><FONT style="BACKGROUND-COLOR: #bfc6d2">No one noticed that the Javascript is commented away? ...</FONT></P>
    <P>
    </P>
    <P>That is an HTML comment, to obscure the Javascript from "older" browsers that don't understand JS.</P>
    <P>I assure you the Javascript will be executed (unless JS is disabled by the user on the browser)</P>
  • Bas 2006-08-31 08:50
    Anonymous:

    <P><FONT style="BACKGROUND-COLOR: #bfc6d2">No one noticed that the Javascript is commented away? ...</FONT></P>
    <P>
    </P>
    <P>Strangely enough, that's because more browsers will be able to&nbsp;use it then..</P>
  • TheRider 2006-08-31 09:32
    snoofle:
    Anonymous:
    Anonymous:

    <p>Notice the bolded parts.&nbsp; When the page loads, all the boxes are checked.&nbsp; If you submit without un-checking and re-checking the box you want, there is no value in the "checkedValues" field.</p>
    <p>
    </p>
    <p>Wait, I was wrong.&nbsp; That doesn't say "checked" it says "on".&nbsp; This was so stupid I mentally filled in what he <em>should have been doing</em> instead of what he actually did.</p>
    <p>Wow, that's a lot of work to be so wrong.</p>
    <p>
    </p>
    <p>Web-neophyte here - I thought check boxes could only be true/false, or possibly [un]checked. "On" ???</p>
    <br>It can also be FileNotFound<br>
  • Me 2006-08-31 09:51
    Anonymous:
    Anonymous:

    <p>Dare I say "Javascript has the best WTF's" ?</p>
    <p>
    </p>
    <p>Somehow it often does :-)</p>
    <p>I had something of&nbsp;a WTF from Javascript yesterday, but I'm going to blame Javascript rather than myself for it.&nbsp; But I might well be to blame due to my lack of experience with Javascript due to the fact that I avoid it whenever possible.&nbsp; Yesterday, I was creating a Date object and populating it with data from a form.&nbsp; Below is a simplified version of what I did:</p>

    var date = new Date();<br>
    date.setYear(2000);<br>
    date.setMonth(1); // 1 for February, since it's zero-based<br>
    date.setDate(10);<br>

    <p>Whenever I set it to February, the outcome would magically be March.&nbsp; It took a good few minutes of confusion before I figured out what was happening.&nbsp; The Date contructor was initialising the date to "now" (i.e. yesterday which was 30 August 2006), which is fine because I'm just going to overwrite it anyway.&nbsp; I set the year to 2000, which was fine.&nbsp; Then I set the month to February.&nbsp; But because the day field was already initialised to 30 by the constructor, Javascript thought I was clearly stupid for wanting the 30th of February and changed it to 2nd of March for me behind my back.&nbsp; Then I set the day to 10, which overwrote half of Javascript's automagic befuddling.&nbsp; This left it looking like the only thing that had happened was that Javascript was somehow allergic to February.&nbsp; Of course the potential for this to happen will only happen on the last few days of the month.</p>
    <p>I fixed it with a big table of carefully worked out cases for when to decrement the month after this had happened.&nbsp; No I didn't because that would have been a real WTF.&nbsp; I read the docs and realised I should just do:</p>

    var Date = new Date(2000,1,10);
    <br><br>Or you could have just set the day before the month.<br>
  • Sofal 2006-08-31 10:15
    One thing I've found very annoying about the whole "name[]" thing that PHP requires is that when you actually <i>do</i> want to access one of these form objects in the JavaScript somewhere you can't just use:<br><br>document.formName.name[]<br><br>Nor can you use (for obvious reasons):<br><br>document.formName.name<br><br>What I eventually had to do was kludgey around it somehow (I can't remember what I did off the top of my head). This is way I think the "name[]" style required by PHP is lame. Anyone have a good way to get around this garbage?<br>
  • Me 2006-08-31 10:33
    Anonymous:
    One thing I've found very annoying about the whole "name[]" thing that PHP requires is that when you actually <i>do</i> want to access one of these form objects in the JavaScript somewhere you can't just use:<br><br>document.formName.name[]<br><br>Nor can you use (for obvious reasons):<br><br>document.formName.name<br><br>What I eventually had to do was kludgey around it somehow (I can't remember what I did off the top of my head). This is way I think the "name[]" style required by PHP is lame. Anyone have a good way to get around this garbage?<br>
    <br><br>Instead of using $_GET or $_POST, use $_SERVER['argv'] and you should be able to walk through making your own name array.<br>
  • Rich 2006-08-31 10:38
    Anonymous:
    One thing I've found very annoying about the whole "name[]" thing that PHP requires is that when you actually <i>do</i> want to access one of these form objects in the JavaScript somewhere you can't just use:<br><br>document.formName.name[]<br><br>Nor can you use (for obvious reasons):<br><br>document.formName.name<br><br>What I eventually had to do was kludgey around it somehow (I can't remember what I did off the top of my head). This is way I think the "name[]" style required by PHP is lame. Anyone have a good way to get around this garbage?<br>
    <br><br>document.formName.elements['name'] I believe.<br>
  • Rich 2006-08-31 10:39
    Anonymous:
    <br>document.formName.elements['name'] I believe.<br>
    <br>Oops<br><br>document.formName.elements['name[]']<br>
  • JL 2006-08-31 10:43
    Arancaytar:
    Hm... so if I got that right, the author of that Javascript didn't trust HTML forms, and instead wrote his own submit-function? Brillant.
    <br>There are cases when you actually might want to do this.&nbsp; For instance, if you are displaying many rows from a database search in an HTML table, you'd probably want to split the search result across multiple webpages.&nbsp; Then if you add a checkbox to each row to allow the user to select multiple rows, you need somewhere to store the states of the checkboxes that are on other pages.&nbsp; If you don't want to store the state on the server, a hidden form field with comma-separated ids works pretty well.&nbsp; And if you're validating the form input on the server anyway, then it doesn't really matter if you update the checkbox state on the server or the client; with the latter, you'd end up with something pretty similar to this, at least in the generated HTML.<br><br>Of course, that's a lot of "if"s, many of which don't apply here, but the overall design is not unreasonable.&nbsp; Perhaps the author copied it from another context where it did make sense?<br>
  • Wombat 2006-08-31 11:37
    Anonymous:
    Anonymous:

    <P>
     var Date = new Date(2000,1,10); 
    <BR><BR>Or you could have just set the day before the month.<BR>
    </P>
    <P>That's the first thing that occurred to me, but it can suffer from the same problem in a slightly different way.&nbsp; </P>
    <P>For example, if "now"&nbsp;is 10th&nbsp;February and I want to set the date to 30th August:&nbsp;I create the Date with the default constructor and set the day first.&nbsp; Javascript&nbsp;will think "stupid programmer has specified 30th February, I think that he really means 2nd March (unless it's&nbsp;a leap year in which case it will be 1st March)" and will change the day to 2 rather than 30.&nbsp; Then I'll set the month to August and the result will be 2nd August.</P>
    <P>Best&nbsp;just to avoid the whole matter by using&nbsp;the other&nbsp;constructor.</P>
  • masklinn 2006-08-31 12:27
    <blockquote><p>One thing I've found very annoying about the whole "name[]" thing that PHP requires is that when you actually do want to access one of these form objects in the JavaScript somewhere you can't just use:</p></blockquote>
    <p>How about giving them a unique ID and accessing your elements in a sane way such as:</p>
    <blockquote><pre>document.getElementById('your-unique-name')</pre></blockquote>
    <p>?</p>
    <p>And object notation is equivalent to hash notation in JS, so you could probably write <code>document.formName['name[]']</code> as well</p>
  • Sofal 2006-08-31 13:00
    <blockquote>And object notation is equivalent to hash notation in JS, so you could probably write document.formName['name[]'] as well</blockquote><br>Man I didn't even know you could use hash notation like that in JavaScript. Just goes to show how much I know. Thanks!<br>
  • UTU 2006-08-31 13:26
    Anonymous:
    <blockquote>
    you could probably write document.formName['name[]'] as well
    </blockquote><br>Man I didn't even know you could use hash notation like that in JavaScript. Just goes to show how much I know. Thanks!<br>
    <br><br>Please forget you ever heard that. It's so 1990's...<br>
  • White 2006-08-31 16:59
    <P>I got a kick out of:</P>
    <P><FONT color=#ff0000><SPAN style="COLOR: #0000ff">&lt;</SPAN><SPAN style="COLOR: #800000">input</SPAN><SPAN style="COLOR: #ff0000"> class<SPAN style="COLOR: #0000ff">="button"</SPAN> type<SPAN style="COLOR: #0000ff">="<STRONG>button</STRONG>"</SPAN> value<SPAN style="COLOR: #0000ff">="Submit"</SPAN> onclick<SPAN style="COLOR: #0000ff">="<STRONG>submit()</STRONG>"</SPAN> </SPAN><SPAN style="COLOR: #0000ff">/&gt;</SPAN></FONT></P>
    <P>and the ...</P>
    <P><FONT color=#ff0000>function submit()<BR>{<BR>&nbsp; <STRONG>document.location.href</STRONG> = 'insert.php?chosen=' + <BR>&nbsp;&nbsp;&nbsp;&nbsp; document.selecter.checkedValues.value;<BR><STRONG>&nbsp; return false;<BR></STRONG>}<BR></FONT></P>
    <P>submit() redirects, so it never gets to the&nbsp;return. Better yet, the onclick event never requests a return ... I think the original author may have been thinking of:&nbsp;<STRONG>&lt;form onsubmit="return submit()"&gt;</STRONG> ... like for some validation routine, or something.</P>
    <P>FYI: A&nbsp;checkbox with&nbsp;<STRONG>value="ON"</STRONG>&nbsp;usually occurs, by default,&nbsp;when you drag-n-drop a checkbox object from many graphical HTML designers, like&nbsp;Frontpage, Dreamweaver, etc.</P>
  • DZ-Jay 2006-09-02 06:11
    ammoQ:
    CodeRage:
    <br>Yeeesh, I'm glad I don't use PHP.&nbsp; How hard is it to parse the key/value pairs in the http post or get, and then build an array for any key that has more than one occurance...Anyway, thanks to all for clarifying this to me.<br>
    <br><br>The problem is that if there is excactly one occurrence, it might be just by pure luck, because the user checked one of several checkboxes. The program expects an array and crashes; unfortunately, in PHP, to make things simple, the program cannot tell the HTTP parser if it expects a single occurrence (therefore a simple variable) or an array.<br>
    <br><br>That seems like a good point.&nbsp; However, it is pretty easy to work around that issue.&nbsp; Why not make the accessors to the form data overloaded for both cases?&nbsp; If the application requests the value from an array, but there is exactly one key with that name, return an array of a single item.&nbsp; If the application requests the value as a scalar, return it.<br><br>As an added bonus, you could make it return a flatten, comma-separated list of values if there is more than one key with the same name, but the application requested a scalar value.&nbsp; This is the way some other frameworks work.&nbsp; Then the intricasies of how the web form is composed or the request is handled, are abstracted from the application developer; while at the same time, the intricasies of how the form is going to be processed by the application, is abstracted from the web designer.<br><br>&nbsp;&nbsp;&nbsp; -dZ.<br><br>-- <br>Whiskey Tango CAPTCHA<br>
  • DZ-Jay 2006-09-02 06:22
    qbolec:
    <p>Is it just me, or naming all check-boxes "chosen" (or in general in with the same name) is a little bit counter-intuitive? I prefer to think, that check-boxes means items that you want to or don't want to choose, so each of them is separate thing, so I usually name them "choice_0",...,"choice_100", so then you can just perform in&nbsp; PHP simple scan</p>
    <br><br>It depends on the context in which the checkboxes are used.&nbsp; If you have unrelated options such as:<br><br>Program Options:<br>[ ] Enable Foo<br>[ ] Enable Bar<br>[ ] Activate actuator<br>[ ] Actuate activator<br>[ ] Use the ascension-descension compression tension extension<br><br>Then you may one each to have its own name so that you may treat them individually.&nbsp; However, if you have a multiple choice list from where the user may check more than one, such as:<br><br>What flavors of ice cream do you like:<br>[ ] Mocholate<br>[ ] Granilla<br>[ ] Fishtachio<br><br>Then you may set them all up with the same name, so that you may treat them as an array of options.<br><br>&nbsp;&nbsp;&nbsp; -dZ.<br><br><br>
  • ammoQ 2006-09-02 06:50
    DZ-Jay:
    <br>Why not make the accessors to the form data overloaded for both cases?&nbsp; If the application requests the value from an array, but there is exactly one key with that name, return an array of a single item.&nbsp; If the application requests the value as a scalar, return it.<br><br>As an added bonus, you could make it return a flatten, comma-separated list of values if there is more than one key with the same name, but the application requested a scalar value.<br>
    <br><br>IMO a very reasonable proposal. Why doesn't PHP offer that by default? I know, this is one of the unanswerable PHP questions, just like "why does a language especially targeted towards database applications have seperate APIs for each database system?"<br>
  • TeeSee 2006-09-05 08:12
    Anaerin:
    I deal with ASP a lot. Essentially all parameters passed in are "StringList"s. The default return value of a StringList is all elements concatenated with commas.<br><br>So, for the URL: thing.asp?test=1&amp;test=2<br><br>Request.QueryString("Test")="1,2"<br><br>However, you can also do:<br><br>Request.QueryString("Test").Count=2<br>Request.QueryString("Test").Value(0)="1"<br>Request.QueryString("Test").Value(1)="2"<br><br>(Which can be shortened down to Request.QueryString("Test")(0) as "Value" is the default parameter).<br><br>So there's no problems with commas, if you use the objects the way they're meant to be used.<br>
    <br><br>That looks like VB to me. I can find nothing like a 'default return' in the documentation (there can be no such thing). If Request.QueryString("x") is a list of strings, then it's not a string. It may have an implicit cast to string (bad. Implicit casts should never lose information).<br><br>In fact, the QueryString.Item property is the same as the index or whatever, so QueryString["a"] is the same as QueryString.Item["a"]. Item returns a string. Always. If you want the list of strings, use QueryString.GetValues("a"), which returns a string array.<br><br>If VB has other atrocities which let this work in strange and wonderful ways, I really don't want to know. I don't know of any language that does things based on the "expected return type" - type inference almost always goes one way. That's why languages don't let you overload functions differing only in return type. Otherwise, you get braindead results like (int)(float)f(), which may or may not be different from (int)f().<br>
  • TeeSee 2006-09-05 08:14
    Anonymous:
    ... For instance, if you are displaying many rows from a database search in an HTML table, you'd probably want to split the search result across multiple webpages.&nbsp; .....&nbsp; If you don't want to store the state on the server, a hidden form field with comma-separated ids works pretty well. <br><br>Of course, that's a lot of "if"s, many of which don't apply here, but the overall design is not unreasonable.&nbsp; Perhaps the author copied it from another context where it did make sense?<br>
    <br><br>If you're reloading the page anyway, the server can set the 'checked' property of the checkboxes fine, all by itself.<br><br>Maybe there are sensible reasons, but only if the javascript parses the value later on the same page.<br><br>And the rule about JavaScript? The page should work just fine without it. If it needs javascript, it's badly designed, obviously by someone who knows nothing about http.<br>
  • TeeSee 2006-09-05 08:42
    ammoQ:
    Anonymous:
    <br>Simple, have $_REQUEST, $_POST and $_GET that work the normal way and have $_REQUEST_ARRAYS, [etc] that return all request values as arrays (whether multi-valued or not). Or have a function that looks into the GET or POST data and works an array if you'd rather do it on the fly than take the processing hit up-front (it's possible to do this yourself but it should be a language feature).<br>
    <br>Yes, that would be the way to go, but it's not compatible with existing programs (register_globals anyone?). And I guess it's against their philosophy. I think they rather keep the program simple and taint the HTML code instead.<br>
    <br><br>It *is* compatible with existing programs. Really. Existing programs can use blah[] if they really want to. Sensible programs can use _GET_ARRAY. Servers can be configured to allow the old behaviour.<br><br>And if PHP was half decent, it could return the empty array for anything that isn't defined, which is the only sensible abstraction.<br><br>But having had to use PHP, it's broken anyway. I don't know if it reparses pages or caches them, but it has shortcomings that makes ASP.NET leaps and bounds better, even though ASP.NET isn't perfect (it's like programming in VB or JavaScript or CF - people who use it tend to have no idea what's going on).<br>
  • TeeSee 2006-09-05 08:42
    Anonymous:
    ....&nbsp; I read the docs and realised I should just do:

    var Date = new Date(2000,1,10);
    <br><br>Or you could have just set the day before the month.<br>
    <br><br>Wrong! Then, when it *is* february, and you set the date to march 29, first it sets it to feb 29 -&gt; mar 1 (on a normal year) and then to march 1 again.<br><br>This is why I hate badly designed date classes.<br><br>
    Anonymous:
    One day, someone will implement a date object that makes sence.<br><p>Well, ok, maybe not, but the hope keeps me going.
    </p>Java's Date is designed decently, though it should be renamed Time (distinct concept from TimeOfDay). They moved all Calendar functions to Calendar, and there are different calendars, not all of which have months (I think?).<br><br>What someone really needs to do is design something that handles TAI, UTC, and timezone-settings correctly. Calling anything "UTC" on a computer that isn't actively recieving leap-second info is wrong - you get a one-second error if you miss a leapsecond. The better way would be to store the difference to TAI in the timestamp as well (this also lets you deal with times a few years into the future)<br><br>Most unfortunately, the POSIX spec says that time() and gettimeofday() effectively replay leap second as the next second (it returns day*86400+seconds, so day 0 second 86400 and day 1 second 0 are equal). NTP replays leapseconds as the previous second. And other really bad designs.<br><br>I call for all timestamps to be TAI.<br><br>
    Anonymous:
    How do you pronounce "TTWTASO"?&nbsp; It's a great
    design pattern in need of a better acronym.&nbsp; I can't wait to start my
    next project and walk up to the current developers and say: Hi guys I
    was looking over the code and I got to say this was an excellent use of
    the TTWTASO design pattern.<br>
    <br>
    <br>
    I propose "t-tw_t-assh_l_", with a stutter. Blanked because I don't know if it'll be deleted if I don't (or even if I do).<br>
  • iwpg 2006-09-05 09:10
    <P>
    TeeSee:
    I don't know of any language that does things based on the "expected return type" - type inference almost always goes one way. That's why languages don't let you overload functions differing only in return type. Otherwise, you get braindead results like (int)(float)f(), which may or may not be different from (int)f().<BR>
    </P>
    <P>Perl allows a function to tell whether it was called in list, scalar or void context, and change its behaviour accordingly: <A href="http://search.cpan.org/dist/perl/pod/perlfunc.pod#wantarray">http://search.cpan.org/dist/perl/pod/perlfunc.pod#wantarray</A>.&nbsp; Haskell allows overloading on the return type, for example <A href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v%3AfromInteger">http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v%3AfromInteger</A>.&nbsp; There are probably other languages that have something similar - IIRC someone here mentioned a while back that Ada could do it.</P>
    <P>
    TeeSee:
    Wrong! Then, when it *is* february, and you set the date to march 29, first it sets it to feb 29 -&gt; mar 1 (on a normal year) and then to march 1 again.<BR><BR>This is why I hate badly designed date classes.<BR><BR>
    Anonymous:
    One day, someone will implement a date object that makes sence.<BR></P>
    <P>Well, ok, maybe not, but the hope keeps me going.
    </P>
    <P>Java's Date is designed decently, though it should be renamed Time (distinct concept from TimeOfDay).
    </P>
    <P>Do you mean this one: <A href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Date.html">http://java.sun.com/j2se/1.5.0/docs/api/java/util/Date.html</A>?&nbsp; Because it behaves the same as JavaScript's Date in this case, and&nbsp;IIRC the JavaScript one is actually just a straightforward translation of the Java one.</P>
  • TeeSee 2006-09-06 07:58
    Java's Date is designed decently, though it should be renamed Time (distinct concept from TimeOfDay).

    <p>Do you mean this one: <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Date.html">http://java.sun.com/j2se/1.5.0/docs/api/java/util/Date.html</a>?&nbsp; Because it behaves the same as JavaScript's Date in this case, and&nbsp;IIRC the JavaScript one is actually just a straightforward translation of the Java one.</p>
    <br><br>They realised it was a WTF and deprecated anything to do with calendars in Date (except toString(), which is an allowable exception, though perhaps it should display UTC). A Date is an instant in time (to some precision), and functions to convert it to calendar dates and back are in Calendar. And if you use Calendar's set() methods, you won't get this WTF. GregorianCalendar improves on it a bit more - one month after Jan 31 is Feb 28/29.<br><br>.NET has yet to make the distinction.<br>